Java Code Examples for android.nfc.tech.IsoDep#connect()
The following examples show how to use
android.nfc.tech.IsoDep#connect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidCard.java From nordpol with MIT License | 7 votes |
public static AndroidCard get(Tag tag) throws IOException { IsoDep card = IsoDep.get(tag); if(card != null) { /* Workaround for the Samsung Galaxy S5 (since the * first connection always hangs on transceive). * TODO: This could be improved if we could identify * Samsung Galaxy S5 devices */ card.connect(); card.close(); return new AndroidCard(card); } else { return null; } }
Example 2
Source File: AndroidCard.java From GreenBits with GNU General Public License v3.0 | 6 votes |
public static AndroidCard get(Tag tag) throws IOException { IsoDep card = IsoDep.get(tag); /* Workaround for the Samsung Galaxy S5 (since the * first connection always hangs on transceive). * TODO: This could be improved if we could identify * Samsung Galaxy S5 devices */ card.connect(); card.close(); if(card != null) { return new AndroidCard(card); } else { return null; } }
Example 3
Source File: AndroidCard.java From WalletCordova with GNU Lesser General Public License v2.1 | 6 votes |
public static AndroidCard get(Tag tag) throws IOException { IsoDep card = IsoDep.get(tag); /* Workaround for the Samsung Galaxy S5 (since the * first connection always hangs on transceive). * TODO: This could be improved if we could identify * Samsung Galaxy S5 devices */ card.connect(); card.close(); if(card != null) { return new AndroidCard(card); } else { return null; } }
Example 4
Source File: LoyaltyCardReader.java From android-CardReader with Apache License 2.0 | 6 votes |
/** * Callback when a new tag is discovered by the system. * * <p>Communication with the card should take place here. * * @param tag Discovered tag */ @Override public void onTagDiscovered(Tag tag) { Log.i(TAG, "New tag discovered"); // Android's Host-based Card Emulation (HCE) feature implements the ISO-DEP (ISO 14443-4) // protocol. // // In order to communicate with a device using HCE, the discovered tag should be processed // using the IsoDep class. IsoDep isoDep = IsoDep.get(tag); if (isoDep != null) { try { // Connect to the remote NFC device isoDep.connect(); // Build SELECT AID command for our loyalty card service. // This command tells the remote device which service we wish to communicate with. Log.i(TAG, "Requesting remote AID: " + SAMPLE_LOYALTY_CARD_AID); byte[] command = BuildSelectApdu(SAMPLE_LOYALTY_CARD_AID); // Send command to remote device Log.i(TAG, "Sending: " + ByteArrayToHexString(command)); byte[] result = isoDep.transceive(command); // If AID is successfully selected, 0x9000 is returned as the status word (last 2 // bytes of the result) by convention. Everything before the status word is // optional payload, which is used here to hold the account number. int resultLength = result.length; byte[] statusWord = {result[resultLength-2], result[resultLength-1]}; byte[] payload = Arrays.copyOf(result, resultLength-2); if (Arrays.equals(SELECT_OK_SW, statusWord)) { // The remote NFC device will immediately respond with its stored account number String accountNumber = new String(payload, "UTF-8"); Log.i(TAG, "Received: " + accountNumber); // Inform CardReaderFragment of received account number mAccountCallback.get().onAccountReceived(accountNumber); } } catch (IOException e) { Log.e(TAG, "Error communicating with card: " + e.toString()); } } }
Example 5
Source File: NfcSession.java From yubikit-android with Apache License 2.0 | 5 votes |
@Override public @NonNull Iso7816Connection openIso7816Connection() throws IOException { IsoDep card = IsoDep.get(tag); if (card == null) { throw new IOException("the tag does not support ISO-DEP"); } card.connect(); return new NfcIso7816Connection(card); }
Example 6
Source File: NfcManager.java From nfcspy with GNU General Public License v3.0 | 5 votes |
static byte[] transceiveApdu(IsoDep tag, byte[] cmd) { if (tag != null) { try { if (!tag.isConnected()) { tag.connect(); tag.setTimeout(10000); } return tag.transceive(cmd); } catch (Exception e) { } } return null; }