-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-增加扫描头广播内容解析功能
- Loading branch information
Showing
4 changed files
with
83 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
arms/src/main/java/com/rouxinpai/arms/receiver/BarcodeScanningReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.rouxinpai.arms.receiver | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
|
||
/** | ||
* author : Saxxhw | ||
* email : [email protected] | ||
* time : 2022/12/27 17:25 | ||
* desc : | ||
*/ | ||
class BarcodeScanningReceiver: BroadcastReceiver() { | ||
|
||
companion object { | ||
// 广播动作 | ||
const val ACTION = "com.android.scanner.broadcast" | ||
// | ||
private const val EXTRA = "scandata" | ||
} | ||
|
||
override fun onReceive(context: Context?, intent: Intent?) { | ||
if (context == null || intent == null) { | ||
return | ||
} | ||
if (context is OnScanListener) { | ||
val value = intent.getStringExtra(EXTRA) | ||
if (value != null && value.isNotBlank()) { | ||
context.onScanned(value) | ||
} | ||
} | ||
} | ||
|
||
interface OnScanListener { | ||
fun onScanned(value: String) | ||
} | ||
} |