@@ -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)"
@@ -329,8 +330,10 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
329330 val timeout = call.argument<Int >(" timeout" )!!
330331 // technology and option bits are set in Dart code
331332 val technologies = call.argument<Int >(" technologies" )!!
333+ val extraPresenceDelay = call.argument<Int >(" extra_reader_presence_check_delay" )
334+
332335 runOnNfcThread(result, " Poll" ) {
333- pollTag(nfcAdapter, result, timeout, technologies)
336+ pollTag(nfcAdapter, result, timeout, technologies, extraPresenceDelay )
334337 }
335338 }
336339
@@ -583,8 +586,7 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
583586
584587 override fun onDetachedFromActivityForConfigChanges () {}
585588
586- private fun pollTag (nfcAdapter : NfcAdapter , result : Result , timeout : Int , technologies : Int ) {
587-
589+ private fun pollTag (nfcAdapter : NfcAdapter , result : Result , timeout : Int , technologies : Int , extraReaderPresenceCheckDelay : Int? ) {
588590 pollingTimeoutTask = Timer ().schedule(timeout.toLong()) {
589591 try {
590592 if (activity.get() != null ) {
@@ -604,7 +606,11 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
604606 result.success(jsonResult)
605607 }
606608
607- nfcAdapter.enableReaderMode(activity.get(), pollHandler, technologies, null )
609+ val options = Bundle ()
610+ if (extraReaderPresenceCheckDelay != null ) {
611+ options.putInt(EXTRA_READER_PRESENCE_CHECK_DELAY , extraReaderPresenceCheckDelay)
612+ }
613+ nfcAdapter.enableReaderMode(activity.get(), pollHandler, technologies, options)
608614 }
609615
610616 private class MethodResultWrapper (result : Result ) : Result {
0 commit comments