diff --git a/src/android/RedLightScan.java b/src/android/RedLightScan.java index dffe554..cc6eb44 100644 --- a/src/android/RedLightScan.java +++ b/src/android/RedLightScan.java @@ -24,6 +24,7 @@ public class RedLightScan extends CordovaPlugin { private static String TAG = RedLightScan.class.getSimpleName(); private ScanUtil scanUtil; private CallbackContext callbackContext; + private boolean receiverRegisted = false; // BroadcastReceiver to receiver scan data private BroadcastReceiver receiver = new BroadcastReceiver() { @@ -88,11 +89,15 @@ public class RedLightScan extends CordovaPlugin { IntentFilter filter = new IntentFilter(); filter.addAction("com.rfid.SCAN"); webView.getContext().registerReceiver(receiver, filter); + this.receiverRegisted = true; + Log.d(TAG, "RedLightScan receiver registed"); } private void unregisterReceiver() { - if (receiver != null) { + if (this.receiverRegisted) { webView.getContext().unregisterReceiver(receiver); + this.receiverRegisted = false; + Log.d(TAG, "RedLightScan receiver unregisted"); } }