@Override public void onDestroy() { cordova.getActivity().getApplicationContext().unregisterReceiver(mHeadsetReceiver); cordova.getActivity().getApplicationContext().unregisterReceiver(mNoisyAudioStreamReceiver); if (mMTSCRA != null) mMTSCRA.closeDevice(); super.onDestroy(); }
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Unhandled execute call: " + action); if (action.equals("openDevice")) { if (mMTSCRA == null) { InitializeDevice(); } if (mbAudioConnected) { if (mMTSCRA.getDeviceType() == MagTekSCRA.DEVICE_TYPE_AUDIO) { // Thread tSetupAudioParams = new Thread() { // public void run() { try { mStringAudioConfigResult = setupAudioParameters(); } catch (Exception ex) { mStringAudioConfigResult = "Error:" + ex.getMessage(); } // } // } // tSetupAudioParams.start(); } else { } mMTSCRA.openDevice(); pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.isDeviceConnected()); } else { pr = new PluginResult(PluginResult.Status.ERROR, "No reader attached."); } } else if (action.equals("closeDevice")) { mMTSCRA.closeDevice(); pr = new PluginResult(PluginResult.Status.OK, !mMTSCRA.isDeviceConnected()); } else if (action.equals("isDeviceConnected")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.isDeviceConnected()); } else if (action.equals("isDeviceOpened")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.isDeviceConnected()); } else if (action.equals("clearCardData")) { pr = new PluginResult(PluginResult.Status.OK); } /* else if(action.equals("setCardData")) { try { ; } } else if(action.equals("getTrackDecodeStatus")) { try { ; } } */ else if (action.equals("getTrack1")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack1()); } else if (action.equals("getTrack2")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack2()); } else if (action.equals("getTrack3")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack3()); } else if (action.equals("getTrack1Masked")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack1Masked()); } else if (action.equals("getTrack2Masked")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack2Masked()); } else if (action.equals("getTrack3Masked")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack3Masked()); } else if (action.equals("getMagnePrintStatus")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getMagnePrintStatus()); } else if (action.equals("getMagnePrint")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getMagnePrint()); } else if (action.equals("getDeviceSerial")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getDeviceSerial()); } else if (action.equals("getSessionID")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getSessionID()); } /* else if(action.equals("setDeviceProtocolString")) { try { ; } } */ else if (action.equals("listenForEvents")) { pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); mEventListenerCb = callbackContext; } else if (action.equals("getCardName")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardName()); } else if (action.equals("getCardIIN")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardIIN()); } else if (action.equals("getCardLast4")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardLast4()); } else if (action.equals("getCardExpDate")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardExpDate()); } else if (action.equals("getCardServiceCode")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardServiceCode()); } else if (action.equals("getCardStatus")) { pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardStatus()); } /* else if(action.equals("setDeviceType")) { try { ; } } */ else if (action.equals("setDeviceType")) {; } callbackContext.sendPluginResult(pr); return true; }