@@ -441,13 +441,17 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
441
441
private fun pollTag (nfcAdapter : NfcAdapter , result : Result , timeout : Int , technologies : Int ) {
442
442
443
443
pollingTimeoutTask = Timer ().schedule(timeout.toLong()) {
444
- if (activity.get() != null ) {
445
- nfcAdapter.disableReaderMode(activity.get())
444
+ try {
445
+ if (activity.get() != null ) {
446
+ nfcAdapter.disableReaderMode(activity.get())
447
+ }
448
+ } catch (ex: Exception ) {
449
+ Log .w(TAG , " Cannot disable reader mode" , ex)
446
450
}
447
451
result.error(" 408" , " Polling tag timeout" , null )
448
452
}
449
453
450
- nfcAdapter.enableReaderMode(activity.get(), { tag ->
454
+ val pollHandler : NfcAdapter . ReaderCallback = { tag ->
451
455
pollingTimeoutTask?.cancel()
452
456
453
457
// common fields
@@ -592,8 +596,14 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
592
596
}
593
597
594
598
result.success(jsonResult.toString())
599
+ }
595
600
596
- }, technologies, null )
601
+ try {
602
+ nfcAdapter.enableReaderMode(activity.get(), pollHandler, technologies, null )
603
+ } catch (ex: Exception ) {
604
+ Log .e(TAG , " Cannot enable reader mode" , ex)
605
+ result.error(" 500" , " Cannot enable reader mode" , ex.localizedMessage)
606
+ }
597
607
}
598
608
599
609
private class MethodResultWrapper (result : Result ) : Result {
0 commit comments