List of usage examples for android.nfc.tech NfcA get
public static NfcA get(Tag tag)
From source file:com.example.multi_ndef.Frag_Write.java
public boolean varifyTag() { boolean test = false; byte[] NdefSelectAppliFrame = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x07, (byte) 0xD2, (byte) 0x76, (byte) 0x00, (byte) 0x00, (byte) 0x85, (byte) 0x01, (byte) 0x01 }; byte[] CCSelect = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0xE1, (byte) 0x03 }; byte[] CCReadLength = new byte[] { (byte) 0x00, (byte) 0xB0, (byte) 0x00, (byte) 0x00, (byte) 0x0F }; byte[] ndefSelectcmd = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0x00, (byte) 0x01 // Ndef File ID to select };// w w w . j ava 2 s .c o m // int a = 491; byte[] ndefreadlengthcmd = new byte[] { (byte) 0x00, (byte) 0xB0, (byte) 0x00, (byte) 0x00, (byte) 0x6E }; byte[] readBinary = new byte[] { (byte) 0x00, (byte) 0xB0, (byte) 0x00, (byte) 0x00, (byte) 0x0F }; byte[] SYSSelect = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0xE1, (byte) 0x01 }; byte[] response1 = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; byte[] response2 = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; byte[] response3 = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; byte[] response4 = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; byte[] response5 = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; byte[] response6 = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; byte[] response7 = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; byte[] response8 = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; try { IsoDep isoDepCurrentTag = (IsoDep) IsoDep.get(ma.getCurrentTag()); NfcA nfcaTag = (NfcA) NfcA.get(ma.getCurrentTag()); nfcaTag.close(); boolean a; a = isoDepCurrentTag.isConnected(); byte[] at = new byte[10]; //at=isoDepCurrentTag.getAtqa(); isoDepCurrentTag.connect(); int time; time = isoDepCurrentTag.getTimeout(); response1 = isoDepCurrentTag.transceive(NdefSelectAppliFrame); response2 = isoDepCurrentTag.transceive(CCSelect); response3 = isoDepCurrentTag.transceive(CCReadLength); response4 = isoDepCurrentTag.transceive(SYSSelect); response5 = isoDepCurrentTag.transceive(readBinary); int ad = 10; isoDepCurrentTag.close(); } catch (Exception e) { String exp = e.toString(); Toast toast = Toast.makeText(getApplicationContext(), "Tag not found in range. Press back button and re click Write button", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0); toast.show(); } if (response5[8] == (byte) 0x02) { test = true; } else { test = false; } return test; }
From source file:de.syss.MifareClassicTool.Common.java
/** * Check if the tag and the device support the Mifare Classic technology. * @param tag The tag to check.// w w w . j a v a2 s . c om * @param context The context of the package manager. * @return * <ul> * <li>0 - Device and tag support Mifare Classic.</li> * <li>-1 - Device does not support Mifare Classic.</li> * <li>-2 - Tag does not support Mifare Classic.</li> * <li>-3 - Error (tag or context is null).</li> * </ul> */ public static int checkMifareClassicSupport(Tag tag, Context context) { if (tag == null || context == null) { // Error. return -3; } if (Arrays.asList(tag.getTechList()).contains(MifareClassic.class.getName())) { // Device and tag support Mifare Classic. return 0; // This is no longer valid. There are some devices (e.g. LG's F60) // that have this system feature but no Mifare Classic support. // (The F60 has a Broadcom NFC controller.) /* } else if (context.getPackageManager().hasSystemFeature( "com.nxp.mifare")){ // Tag does not support Mifare Classic. return -2; */ } else { // Check if device does not support Mifare Classic. // For doing so, check if the ATQA + SAK of the tag indicate that // it's a Mifare Classic tag. // See: http://www.nxp.com/documents/application_note/AN10833.pdf // (Table 5 and 6) // 0x28 is for some emulated tags. NfcA nfca = NfcA.get(tag); byte[] atqa = nfca.getAtqa(); if (atqa[1] == 0 && (atqa[0] == 4 || atqa[0] == (byte) 0x44 || atqa[0] == 2 || atqa[0] == (byte) 0x42)) { // ATQA says it is most likely a Mifare Classic tag. byte sak = (byte) nfca.getSak(); if (sak == 8 || sak == 9 || sak == (byte) 0x18 || sak == (byte) 0x88 || sak == (byte) 0x28) { // SAK says it is most likely a Mifare Classic tag. // --> Device does not support Mifare Classic. return -1; } } // Nope, it's not the device (most likely). // The tag does not support Mifare Classic. return -2; } }
From source file:net.zjy.zxcardumper.Common.java
/** * Check if the tag and the device support the MIFARE Classic technology. * @param tag The tag to check.//from ww w . j av a 2 s .co m * @param context The context of the package manager. * @return * <ul> * <li>0 - Device and tag support MIFARE Classic.</li> * <li>-1 - Device does not support MIFARE Classic.</li> * <li>-2 - Tag does not support MIFARE Classic.</li> * <li>-3 - Error (tag or context is null).</li> * </ul> */ public static int checkMifareClassicSupport(Tag tag, Context context) { if (tag == null || context == null) { // Error. return -3; } if (Arrays.asList(tag.getTechList()).contains(MifareClassic.class.getName())) { // Device and tag support MIFARE Classic. return 0; // This is no longer valid. There are some devices (e.g. LG's F60) // that have this system feature but no MIFARE Classic support. // (The F60 has a Broadcom NFC controller.) /* } else if (context.getPackageManager().hasSystemFeature( "com.nxp.mifare")){ // Tag does not support MIFARE Classic. return -2; */ } else { // Check if device does not support MIFARE Classic. // For doing so, check if the ATQA + SAK of the tag indicate that // it's a MIFARE Classic tag. // See: http://www.nxp.com/documents/application_note/AN10833.pdf // (Table 5 and 6) // 0x28 is for some emulated tags. NfcA nfca = NfcA.get(tag); byte[] atqa = nfca.getAtqa(); if (atqa[1] == 0 && (atqa[0] == 4 || atqa[0] == (byte) 0x44 || atqa[0] == 2 || atqa[0] == (byte) 0x42)) { // ATQA says it is most likely a MIFARE Classic tag. byte sak = (byte) nfca.getSak(); if (sak == 8 || sak == 9 || sak == (byte) 0x18 || sak == (byte) 0x88 || sak == (byte) 0x28) { // SAK says it is most likely a MIFARE Classic tag. // --> Device does not support MIFARE Classic. return -1; } } // Nope, it's not the device (most likely). // The tag does not support MIFARE Classic. return -2; } }