修正重复添加多个的问题
This commit is contained in:
@@ -373,8 +373,14 @@ fun CameraPreview(onScan: (String) -> Unit) {
|
||||
|
||||
class ZxingAnalyzer(private val onScan: (String) -> Unit) : ImageAnalysis.Analyzer {
|
||||
private val reader = MultiFormatReader()
|
||||
@Volatile
|
||||
private var scanned = false
|
||||
|
||||
override fun analyze(image: ImageProxy) {
|
||||
if (scanned) {
|
||||
image.close()
|
||||
return
|
||||
}
|
||||
val buffer = image.planes[0].buffer
|
||||
val data = ByteArray(buffer.capacity())
|
||||
buffer.get(data)
|
||||
@@ -395,6 +401,7 @@ class ZxingAnalyzer(private val onScan: (String) -> Unit) : ImageAnalysis.Analyz
|
||||
val result = reader.decode(binaryBitmap)
|
||||
val text = result.text
|
||||
if (text.startsWith("otpauth://")) {
|
||||
scanned = true
|
||||
onScan(text)
|
||||
}
|
||||
} catch (e: NotFoundException) {
|
||||
|
||||
Reference in New Issue
Block a user