List of usage examples for android.nfc.tech IsoDep get
public static IsoDep 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 };//from ww w. j a v a 2s . com // 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:com.sigilance.CardEdit.MainActivity.java
protected void handleNdefDiscoveredIntent(Intent intent) throws IOException { Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); isoDep = IsoDep.get(detectedTag); isoDep.setTimeout(100000); // timeout is set to 100 seconds to avoid cancellation during calculation isoDep.connect();/*from w w w .j a v a 2 s . c om*/ byte[] opening = { 0x00, (byte) 0xA4, 0x04, 0x00, 0x06, (byte) 0xD2, 0x76, 0x00, 0x01, 0x24, 0x01, 0x00 }; byte[] response = nfcCommunicate(opening); if (!Arrays.equals(response, SW_ACCEPTED)) { throw new IOException("Initialization failed!"); } byte[] aid = nfcGetData(DO_AID); // If user is touching card for the first time, cache the AID. if (mCurrentAid == null) { mCurrentAid = aid; } // Confirm that they're still tapping the same card. if (!Arrays.equals(aid, mCurrentAid)) { throw new IOException("Serial numbers did not match; did you tap a different card?"); } // With safety checks out of the way, perform pending operations. if (mPendingOperations.size() > 0) { String newAdminPIN = null; for (PendingOperation operation : mPendingOperations) { if (operation instanceof PendingVerifyPinOperation) { PendingVerifyPinOperation op = (PendingVerifyPinOperation) operation; nfcVerifyPIN(op.getSlot(), op.getPin()); // NOTE: We do not remove the verify operation, because if the user wants to // edit another DO, we'll need to transmit it again. } else if (operation instanceof PendingPutDataOperation) { PendingPutDataOperation op = (PendingPutDataOperation) operation; nfcPutData(op.getSlot(), op.getData()); mPendingOperations.remove(op); } else if (operation instanceof PendingChangePinOperation) { PendingChangePinOperation op = (PendingChangePinOperation) operation; nfcModifyPIN(op.getSlot(), op.getOldPin(), op.getNewPin()); if (op.getSlot() == 0x83) newAdminPIN = op.getNewPin(); mPendingOperations.remove(op); Toast.makeText(this, "PIN was changed.", Toast.LENGTH_LONG).show(); } } // If we changed the Admin PIN, we need the VERIFY command to reflect the new PIN. if (newAdminPIN != null) for (PendingOperation operation : mPendingOperations) if (operation instanceof PendingVerifyPinOperation) { PendingVerifyPinOperation op = (PendingVerifyPinOperation) operation; if (op.getSlot() == 0x83) op.setPin(newAdminPIN); } } // Finally, get all the data and show the UI. byte[] cardholderData = nfcGetData(DO_CARDHOLDER_DATA); Iso7816TLV chTlv = Iso7816TLV.readSingle(cardholderData, true); mCardholderName = new String(Iso7816TLV.findRecursive(chTlv, TAG_NAME).mV); mCardholderSex = new String(Iso7816TLV.findRecursive(chTlv, TAG_SEX).mV); mCardholderLanguage = new String(Iso7816TLV.findRecursive(chTlv, TAG_LANGUAGE).mV); mUrl = new String(nfcGetData(DO_URL)); mLoginData = nfcGetData(DO_LOGIN_DATA); byte[] appData = nfcGetData(DO_APPLICATION_DATA); Iso7816TLV appTlv = Iso7816TLV.readSingle(appData, true); byte[] fingerprints = Iso7816TLV.findRecursive(appTlv, TAG_FINGERPRINTS).mV; mSigKeyFingerprint = hexString(Arrays.copyOfRange(fingerprints, 0, 20)); mEncKeyFingerprint = hexString(Arrays.copyOfRange(fingerprints, 20, 40)); mAuthKeyFingerprint = hexString(Arrays.copyOfRange(fingerprints, 40, 60)); byte[] timestamps = Iso7816TLV.findRecursive(appTlv, TAG_TIMESTAMPS).mV; mSigKeyTimestamp = unsignedFromByteArray(Arrays.copyOfRange(timestamps, 0, 4)); mEncKeyTimestamp = unsignedFromByteArray(Arrays.copyOfRange(timestamps, 4, 8)); mAuthKeyTimestamp = unsignedFromByteArray(Arrays.copyOfRange(timestamps, 8, 12)); mPwStatusBytes = nfcGetData(DO_PW_STATUS_BYTES); byte[] secData = nfcGetData(DO_SECURITY_TEMPLATE); Iso7816TLV secTlv = Iso7816TLV.readSingle(secData, true); byte[] sigCount = { 0, 0, 0, 0 }; byte[] sigCountFromCard = Iso7816TLV.findRecursive(secTlv, TAG_SIG_COUNT).mV; System.arraycopy(sigCountFromCard, 0, sigCount, 1, 3); mSignatureCount = ByteBuffer.wrap(sigCount).getInt(); refreshUi(); }