Swipe Reader SDK
Introduction
The SwipeReaderSDK is a library designed to simplify the integration of swipe card reading functionality into Android applications. This SDK is for reading magnetic stripe card data.
Integrating the SwipeReaderSDK
This guide details the steps to integrate the SwipeReaderSDK into your Android project.
Prerequisites
- Your Android project
- SwipeReader kit
The swipe_reader.aar file is provided with the kit. Download from here
Downloading the SwipeReaderSDK
- Locate the
swipe_reader.aar
file provided with your SwipeReader kit. - Copy the
swipe_reader.aar
file to your project directory.
Configuring Gradle Dependencies
- Open your project's build.gradle file (located at the module level).
- Add the following dependencies within the dependencies block:
implementation files("../libs/swipe_reader.aar")
implementation "com.google.code.gson:gson:2.8.9"
The second line (optional) includes the Gson library (version 2.8.9) as an example dependency. You may need to adjust this based on your project's requirements.
Synchronizing Gradle
Click Sync Project with Gradle Files in Android Studio. This process updates your project with the SwipeReaderSDK and any additional dependencies you've included.
Get Card Details
To start reading swipe cards, call the read() method on the MsrReader instance.
MsrReader msrReader = new MsrReader(context, timeoutInSeconds);
msrReader.read(new SwipeResult() {
@Override
public void onSuccess(String result) {
// Handle successful swipe
}
@Override
public void onFailure(String error) {
// Handle swipe failure
}
@Override
public void onTimeOut(String message) {
// Handle swipe timeout
}
});
Card reading by SDK
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize card reader
MsrReader msrReader = new MsrReader(this, 60);
// Read swipe card
msrReader.read(new SwipeResult() {
@Override
public void onSuccess(String s) {
Log.d("onSuccess", s);
runOnUiThread(()->Toast.makeText(context,s,Toast.LENGTH_SHORT).show());
}
@Override
public void onFailure(String s) {
Log.d("onFailure", s);
runOnUiThread(()->Toast.makeText(context,s,Toast.LENGTH_SHORT).show());
}
@Override
public void onTimeOut(String s) {
Log.d("onTimeOut", s);
runOnUiThread(()->Toast.makeText(context,s,Toast.LENGTH_SHORT).show());
}
});
}
}
Response Fields
Output tag | Type | Format |
---|---|---|
responseCode * | String | 00 |
responseData * | JSON | {”track1”:”527912186188049”,”track2”:”527912186188049”} track1 – Provides data from track1 of card if available track2 – Provides data from track2 of card if available track3 – Provides data from track3 of card if available |
responseMessage * | String | SUCCESS – if data is available FAILURE – If any error while reading the card |
Here the responseData
is a JSON String
The response will indicate success or failure. Here's what some of the outcome looks like:
Success Response
{
"responseCode": "00",
"responseData": "{\"track1\":\"527912186188049\",\"track2\":\"527912186188049\"}",
"responseMessage": "SUCCESS"
}
Failure Response
{
"responseCode": "06",
"responseData": "Failed to read card data",
"responseMessage": "FAILURE"
}
Timeout Response
{
"responseCode": "07",
"responseData": "Card detection timeout",
"responseMessage": "FAILURE"
}
Code | Type | Description |
---|---|---|
00 | Success | The swipe card operation was successful. |
01 | Failure | Please update the timeout to be in the range of 10 to 90 seconds. |
02 | Failure | Unable to support this device model. |
03 | Failure | Unable to initialize card reader. |
04 | Failure | Unable to initialize card reader. Context is null. |
05 | Failure | Unable to support this device model. |
06 | Failure | Failed to open card reader |
07 | Failure | Failed to read card data. |
08 | Timeout | Card detection timeout. |
09 | Failure | Exception in card detection. |
10 | Failure | All track data null. |
11 | Failure | Card detection timeout. |
12 | Failure | We don’t support this device. |
13 | Failure | Swipe reader failed. |
14 | Failure | Device exception. |