I'm trying to implement an Android Activity that detects the IDTech card reader accepts a simple card swipe.
Below is the bare bones structure to my implementation for which I took help from here as well
The code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import IDTech.MSR.XMLManager.StructConfigParameters;
import IDTech.MSR.uniMag.uniMagReader;
import IDTech.MSR.uniMag.uniMagReaderMsg;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements uniMagReaderMsg {
private uniMagReader myUniMagReader = null;
private Button btnSwipe;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(myUniMagReader == null) {
myUniMagReader = new uniMagReader(this,this);
myUniMagReader.setSaveLogEnable(false);
myUniMagReader.setXMLFileNameWithPath(null);
myUniMagReader.loadingConfigurationXMLFile(true);
//myUniMagReader.setVerboseLoggingEnable(true);
myUniMagReader.registerListen();
}
btnSwipe = (Button) findViewById(R.id.button1);
btnSwipe.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
myUniMagReader.startSwipeCard();
}
});
}
@Override
public void onDestroy() {
myUniMagReader.stopSwipeCard();
myUniMagReader.unregisterListen();
myUniMagReader.release();
super.onDestroy();
}
@Override
public boolean getUserGrant(int arg0, String arg1) {
Log.d("UniMag", "getUserGrant -- " + arg1);
return true;
}
@Override
public void onReceiveMsgAutoConfigProgress(int arg0) {
// TODO Auto-generated method stub
Log.d("UniMag", "onReceiveMsgAutoConfigProgress");
}
@Override
public void onReceiveMsgCardData(byte arg0, byte[] arg1) {
Log.d("UniMag", "onReceiveMsgCardData");
Log.d("UniMag", "Successful swipe!");
}
final Handler swipeHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
String text = (String)msg.obj;
TextView dataView = (TextView) findViewById(R.id.text_view);
dataView.setText(text);
}
};
@Override
public void onReceiveMsgCommandResult(int arg0, byte[] arg1) {
Log.d("UniMag", "onReceiveMsgCommandResult");
}
@Override
public void onReceiveMsgConnected() {
Log.d("UniMag", "onReceiveMsgConnected");
Log.d("UniMag", "Card reader is connected.");
}
@Override
public void onReceiveMsgDisconnected() {
Log.d("UniMag", "onReceiveMsgDisconnected");
if(myUniMagReader.isSwipeCardRunning()) {
myUniMagReader.stopSwipeCard();
}
myUniMagReader.release();
}
@Override
public void onReceiveMsgFailureInfo(int arg0, String arg1) {
Log.d("UniMag","onReceiveMsgFailureInfo -- " + arg1);
}
@Override
public void onReceiveMsgSDCardDFailed(String arg0) {
Log.d("UniMag", "onReceiveMsgSDCardDFailed -- " + arg0);
}
@Override
public void onReceiveMsgTimeout(String arg0) {
Log.d("UniMag", "onReceiveMsgTimeout -- " + arg0);
Log.d("UniMag","Timed out!");
}
@Override
public void onReceiveMsgToConnect() {
Log.d("UniMag","Swiper Powered Up");
}
@Override
public void onReceiveMsgToSwipeCard() {
Log.d("UniMag","onReceiveMsgToSwipeCard");
}
@Override
public void onReceiveMsgAutoConfigCompleted(StructConfigParameters arg0) {
Log.d("UniMag", "onReceiveMsgAutoConfigCompleted");
}
}
The issue here is that I only get these two messages in the Logcat "Swiper is powered up" from onReceiveMsgToConnect()
And After a few seconds (maybe 20 sec)
"Timed out!" from onReceiveMsgTimeout() that sends back a string saying unable to connect to device. I have multiple IDTech devices and this happens the same on every device. Also, sometimes if I am lucky enough I do get: "Card reader is connected." from onReceiveMsgConnected() that means it is connected. But this happens very rarely.
Any help would be very appreciated. Thanks!
Okay so I got it working. I was using an older version of the sdk (unimag.reader.android-1.0.0.jar) and the configuration xml file (idt_unimagcfg_default.xml). I simply updated them to the most recent version of the sdk and the xml.
New versions (as of December 2014) SDK: IDT_UniMagSDKAndroid_v4.4.jar - xml: umcfg.4.4.1.xml
And the timeout problem is solved.
P.S: just as a side note, please also do visit their website for any device specific details you might need for the specific card swiper you are using. For example: I was using a "Shuttle, Two-Track Secure Mobile MagStripe Reader" with a "HTC ONE" phone. After going on to this page here I figured that for HTC ONE I need to turn off my "Beats audio" to appropriately use this device. I hope this helps.