Skip to content

Commit

Permalink
Add more null check in Android plugin, fix semlette#61 and semlette#71
Browse files Browse the repository at this point in the history
Signed-off-by: Harry Chen <[email protected]>
  • Loading branch information
Harry-Chen committed May 11, 2022
1 parent cf9a392 commit b4d99f3
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

private fun handleMethodCall(call: MethodCall, result: Result) {

if (activity == null) {
result.error("500", "Cannot call method when not attached to activity", null)
return
}

val nfcAdapter = getDefaultAdapter(activity)

if (nfcAdapter?.isEnabled != true && call.method != "getNFCAvailability") {
Expand Down Expand Up @@ -123,7 +128,9 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
} catch (ex: IOException) {
Log.e(TAG, "Close tag error", ex)
}
nfcAdapter.disableReaderMode(activity)
if (activity != null) {
nfcAdapter.disableReaderMode(activity)
}
result.success("")
}
}
Expand Down Expand Up @@ -301,7 +308,9 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private fun pollTag(nfcAdapter: NfcAdapter, result: Result, timeout: Int, technologies: Int) {

pollingTimeoutTask = Timer().schedule(timeout.toLong()) {
nfcAdapter.disableReaderMode(activity)
if (activity != null) {
nfcAdapter.disableReaderMode(activity)
}
result.error("408", "Polling tag timeout", null)
}

Expand Down

0 comments on commit b4d99f3

Please sign in to comment.