fix: NFC读到卡号后立即停止轮询,避免重复回调
轮询每1秒读一次sysfs,卡片还贴着时会再次读到卡号, 导致回调触发两次→API调两次→音效播放两次。 读到有效卡号后立即stopScan()+return,只触发一次回调。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -82,11 +82,14 @@ class FiseNfcController @Inject constructor() : NfcController {
|
||||
|
||||
// 非空且非全零才算有效卡号(全零=无卡贴近)
|
||||
if (nfcId.isNotEmpty() && nfcId.any { it != '0' }) {
|
||||
Timber.d("NFC控制: 读到卡号 $nfcId")
|
||||
Timber.d("NFC控制: 读到卡号 $nfcId,停止轮询")
|
||||
// 读到有效卡号后立即停止轮询,避免重复回调
|
||||
stopScan()
|
||||
// 切回主线程回调
|
||||
withContext(Dispatchers.Main) {
|
||||
callback(nfcId)
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in New Issue
Block a user