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