MagManager

##
android.device
Class MagManager

    java.lang.Object
      android.device.MagManager

    public class MagManager

extends java.lang.Object

The MagManager class is used to initialize and control the MSR card reader, and has the function of obtaining all data of the card.

To control the MSR card reader with this class, according to the following steps,

1. You can obtain an instance of this class by calling. MagManager manager = new MagManager();
2. Initialize slot for the MSR card reader with `open`.
3. Query whether the MSR card is not swipe with `checkCard`.
4. Get information on all 3 tracks with `getAllStripInfo`.
5. Call `close` to close the slot for MSR card reader.

   For more information about the MSR card reader, read MagManager sample.

Constructor Summary
`MagManager()` The MagManager class is used to initialize and control the MSR card reader.

Method Summary
`int` | `open()` Open the MSR reader.
`int` | `close()` Close the MSR reader.
`int` | `checkCard()` Check if a card swipe action has taken place.
`int` | `getAllStripInfo(byte[] info)` Get information on all 3 tracks.
`int` | `getSingleStripInfo(int strip, byte[] info)` Get specific track information.
`int` | `getEncryptStripInfo(int AlgMode, int keyIndex, byte[] info, byte[] cardNo, byte[] KSN)` Get information on all 3 Encrypt track data and plain text card NO.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MagManager

    public MagManager()

Method Detail

### open

    public int open()

  Open the MSR reader.

  Parameters:
    none
  Returns:
    0 if the open operation succeeds, negative if the operation fails.
  Example:
    `MagManager magManager = new MagManager();
    int ret = magManager.open();
    if (ret != 0) {
    //open failed
    }`

### close

    public int close()

  Close the MSR reader.

  Parameters:
    none
  Returns:
    0 if successful, negative number if failed.
  Example:
    `int ret = magManager.open();
    if(ret == 0) {
    magManager.close();
    }`

### checkCard

    public int checkCard()

  Check if a card swipe action has taken place.

  Parameters:
    none
  Returns:
    0 if card swipe action has been detected, negative number if swipe action has not been detected.
  Example:
    `magManager.open();
    int ret = magManager.checkCard();
    if (ret != 0) {
    //No card swiping detected
    }`

### getAllStripInfo

    public int getAllStripInfo(byte[] info)

  Get information on all track.

  Parameters:
    `info` - To store the information. The information is organized in TLV (tag length value) format. The tag is 1 byte, with the following meaning:
    01 : track 1
    02 : track 2
    03 : track 3
  Returns:
    length of information, 0 if no information.
  Example:
    `magManager.open();
    StringBuffer buffer = new StringBuffer();
    byte[] stripInfo = new byte[1024];
    int allLen = magManager.getAllStripInfo(stripInfo);
    if (allLen > 0) {
    //analytical data, information stored in stripInfo
    int len = stripInfo[1];
    if (len != 0)
    //The first two digits of info should be 01, because it gets information of track 1.
    buffer.append(" strip1: " + new String(stripInfo, 2, len));
    int len2 = stripInfo[3 + len];
    if (len2 != 0)
    //The first two digits of info should be 02, because it gets information of track 2.
    buffer.append(" \nstrip2: " + new String(stripInfo, 4 + len, len2));
    int len3 = stripInfo[5 + len+len2];
    if (len3 != 0 && len3 < 1024)
    //The first two digits of info should be 03, because it gets information of track 3.
    buffer.append(" \nstrip3: " + new String(stripInfo, 6 + len + len2, len3));
    buffer.append("\n");
    }`

### getSingleStripInfo

    public int getSingleStripInfo(int strip,
                                  byte[] info)

  Get specific track information.

  Parameters:
    `strip` - Number of track. Values are as follows:
    1 : track 1
    2 : track 2
    3 : track 3
    `info` - To store the track information. The information is organized in TLV (tag length value) format. The tag is 1 byte, with the following meaning:
    01 : track 1
    02 : track 2
    03 : track 3
  Returns:
    the length of information, 0 if no information.
  Example:
    `StringBuffer buffer = new StringBuffer();
    byte[] info = new byte[1024];
    public static final int TRACK_1 = 1; //For track 1
    int len = magManager.getSingleStripInfo(TRACK_1, info);
    if (len > 0) {
    //analytical data, information stored in info
    //The first two digits of info should be 01, because it gets information of track 1.
    buffer.append(" strip1: " + new String(info, 2, len));
    buffer.append("\n");
    }`

### getEncryptStripInfo

    public int getEncryptStripInfo(int AlgMode,
                                   int keyIndex,
                                   byte[] info,
                                   byte[] cardNo,
                                   byte[] KSN)

  Get information on all 3 Encrypt track data and plain text card NO.

  Parameters:
    `AlgMode` - Data DES algorithm type. 1 is dupkt key.
    `keyIndex` - The DES Key index is 0 to 149.
    `info` - To store the encrypt information. The information is organized in TLV (tag length value) format. The tag is 1 byte, with the following meaning
    01 : track 1
    02 : track 2
    03 : track 3
    `cardNo` - Output. To store the plain text PAN.
    `KSN` - Output. To store the KSN key(10 bytes).
  Returns:
    length of encrypt information, 0 if no information.
  Example:
    `byte[] Info = new byte[1024];
    byte[] cardNo = new byte[1024];
    byte[] KSN = new byte[10];
    int AlgMode = 1;
    int keyIndex = 101;
    int allLen = magManager.getEncryptStripInfo(AlgMode, keyIndex, Info, cardNo, KSN);
    if (allLen > 0) {
    //analytical data
    }`