@@ -8,6 +8,7 @@ import android.nfc.NfcAdapter
88import android.nfc.NfcAdapter.*
99import android.nfc.Tag
1010import android.nfc.tech.*
11+ import android.os.Bundle
1112import android.os.Handler
1213import android.os.HandlerThread
1314import android.os.Looper
@@ -86,13 +87,13 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
8687 Log .e(TAG , " $desc error" , ex)
8788 val excMessage = ex.localizedMessage
8889 when (ex) {
89- is IOException -> result? .error(" 500" , " Communication error" , excMessage)
90- is SecurityException -> result? .error(" 503" , " Tag already removed" , excMessage)
91- is FormatException -> result? .error(" 400" , " NDEF format error" , excMessage)
92- is InvocationTargetException -> result? .error(" 500" , " Communication error" , excMessage)
93- is IllegalArgumentException -> result? .error(" 400" , " Command format error" , excMessage)
94- is NoSuchMethodException -> result? .error(" 405" , " Transceive not supported for this type of card" , excMessage)
95- else -> result? .error(" 500" , " Unhandled error" , excMessage)
90+ is IOException -> result.error(" 500" , " Communication error" , excMessage)
91+ is SecurityException -> result.error(" 503" , " Tag already removed" , excMessage)
92+ is FormatException -> result.error(" 400" , " NDEF format error" , excMessage)
93+ is InvocationTargetException -> result.error(" 500" , " Communication error" , excMessage)
94+ is IllegalArgumentException -> result.error(" 400" , " Command format error" , excMessage)
95+ is NoSuchMethodException -> result.error(" 405" , " Transceive not supported for this type of card" , excMessage)
96+ else -> result.error(" 500" , " Unhandled error" , excMessage)
9697 }
9798 }
9899 }
@@ -141,7 +142,7 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
141142 tagTechnology = isoDep
142143 // historicalBytes() may return null but is wrongly typed as ByteArray!
143144 // https://developer.android.com/reference/kotlin/android/nfc/tech/IsoDep#gethistoricalbytes
144- historicalBytes = ( isoDep.historicalBytes as ByteArray? ) ?.toHexString() ? : " "
145+ historicalBytes = isoDep.historicalBytes?.toHexString() ? : " "
145146 }
146147 tag.techList.contains(MifareClassic ::class .java.name) -> {
147148 standard = " ISO 14443-3 (Type A)"
@@ -604,7 +605,12 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
604605 result.success(jsonResult)
605606 }
606607
607- nfcAdapter.enableReaderMode(activity.get(), pollHandler, technologies, null )
608+ // The EXTRA_READER_PRESENCE_CHECK_DELAY is for fixing an obscure bug with
609+ // some Android versions like LineageOS 17.1 that caused the PACE authentication to fail.
610+ // See https://github.com/privacybydesign/vcmrtd/issues/91 for more info.
611+ val options = Bundle ()
612+ options.putInt(EXTRA_READER_PRESENCE_CHECK_DELAY , 2000 )
613+ nfcAdapter.enableReaderMode(activity.get(), pollHandler, technologies, options)
608614 }
609615
610616 private class MethodResultWrapper (result : Result ) : Result {
0 commit comments