Simple plugin to use uDynamo in android apps made with phonegap.
Install the plugin
$ phonegap plugin add https://github.com/CODESM003/uDynamo-Phonegap-Android.git
Add this to AndroidManifest.xml
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
isDeviceConnected
is used to check if the reader is connected.
It actually checks if anything is plugged in the headphone jack but should be okay for a POS type system.
var success = function() {
alert("Device is connected");
}
var failure = function() {
alert("Device is not connected");
}
udynamo.isDeviceConnected(success, failure);
getSwipeData
opens the device and waits for a card to be swiped then returns the data as json.
var success = function(data) {
alert("Your card track 1 data is " + data.Track1);
}
var failure = function(response) {
if(response === 'Error') {
alert("device is not connected"); // better to check for this with 'isDeviceConnected'
return;
}
alert(response); // The card was not property swiped. Please try again.
}
udynamo.getSwipeData(success, failure);
cancelSwipe
cancels the getSwipeData
request and closes the device.
var success = function() {
alert("Device closed successfully");
}
var failure = function() {
alert("Failed to close the device. Try replugging it.");
}
udynamo.cancelSwipe(success, failure);