public void onDestroy() { MsrInterface.cancelPoll(); isPollCanceled = true; MsrInterface.close(); if (null != waitDataLooper) { waitDataLooper.quit(); } }
private void gotoPoll(int timeout) { Log.d(TAG, this + " gotoPoll"); int pollResult = MsrInterface.poll(timeout); if (0 != pollResult && !isPollCanceled) { Log.d(TAG, this + " gotoPoll"); gotoPoll(timeout); } if (0 == pollResult) { if (isPollCanceled) { this.onDestroy(); } String track1 = msrGetTrackData(0); String track2 = msrGetTrackData(1); String track3 = msrGetTrackData(2); Log.d(TAG, "SwipeCard track1 : " + track1 + " track2 : " + track2 + " track3 : " + track3); if (null == track2) { gotoPoll(timeout); } else { Hashtable<String, String> trackData = new Hashtable<String, String>(); if (track1 != null) { trackData.put("track1", track1); } trackData.put("track2", track2); if (track3 != null) { trackData.put("track3", track3); } else { trackData.put("track3", ""); } trackData.put("cardID", getCardID(track2)); this.listener.onRecvTrackData(trackData); } } }
public void onStart() { if (MsrInterface.open() < 0) { MsrInterface.close(); MsrInterface.open(); } Handler handler = new Handler(waitDataLooper); handler.post( new Runnable() { @Override public void run() { int timeout = 300000; gotoPoll(timeout); } }); }
private String msrGetTrackData(int trackIndex) { int ret = MsrInterface.getTrackError(trackIndex); if (ret < 0) { Log.i(TAG, "msr track" + trackIndex + " error is = " + ret); return null; } byte[] byteArry = new byte[255]; int result = MsrInterface.getTrackData( trackIndex, byteArry, MsrInterface.getTrackDataLength(trackIndex)); if (result > 0) { return new String(byteArry, 0, result); } else { return null; } }