更新 'src/android/RedLightScan.java'
调整注册与取消注册逻辑
This commit is contained in:
parent
9a2f9b2055
commit
fda5173954
@ -86,6 +86,11 @@ public class RedLightScan extends CordovaPlugin {
|
||||
}
|
||||
|
||||
private void registerReceiver() {
|
||||
if (scanUtil == null) {
|
||||
scanUtil = new ScanUtil(cordova.getActivity());
|
||||
//we must set mode to 0 : BroadcastReceiver mode
|
||||
scanUtil.setScanMode(0);
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.rfid.SCAN");
|
||||
webView.getContext().registerReceiver(receiver, filter);
|
||||
@ -94,6 +99,11 @@ public class RedLightScan extends CordovaPlugin {
|
||||
}
|
||||
|
||||
private void unregisterReceiver() {
|
||||
if (scanUtil != null) {
|
||||
scanUtil.setScanMode(1);
|
||||
scanUtil.close();
|
||||
scanUtil = null;
|
||||
}
|
||||
if (this.receiverRegisted) {
|
||||
webView.getContext().unregisterReceiver(receiver);
|
||||
this.receiverRegisted = false;
|
||||
@ -103,13 +113,8 @@ public class RedLightScan extends CordovaPlugin {
|
||||
|
||||
@Override
|
||||
public void onResume(boolean multitasking) {
|
||||
Log.d(TAG, "RedLightScan Resume");
|
||||
super.onResume(multitasking);
|
||||
if (scanUtil == null) {
|
||||
scanUtil = new ScanUtil(cordova.getActivity());
|
||||
//we must set mode to 0 : BroadcastReceiver mode
|
||||
scanUtil.setScanMode(0);
|
||||
}
|
||||
Log.d(TAG, "RedLightScan Resume");
|
||||
this.registerReceiver();
|
||||
}
|
||||
|
||||
@ -117,11 +122,6 @@ public class RedLightScan extends CordovaPlugin {
|
||||
public void onPause(boolean multitasking) {
|
||||
super.onPause(multitasking);
|
||||
Log.d(TAG, "RedLightScan Pause");
|
||||
if (scanUtil != null) {
|
||||
scanUtil.setScanMode(1);
|
||||
scanUtil.close();
|
||||
scanUtil = null;
|
||||
}
|
||||
this.unregisterReceiver();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user