android.nfc.tech.IsoDep Java Examples
The following examples show how to use
android.nfc.tech.IsoDep.
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: Tag.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static HashMap<String, Integer> getTechStringToCodeMap() { HashMap<String, Integer> techStringToCodeMap = new HashMap<String, Integer>(); techStringToCodeMap.put(IsoDep.class.getName(), TagTechnology.ISO_DEP); techStringToCodeMap.put(MifareClassic.class.getName(), TagTechnology.MIFARE_CLASSIC); techStringToCodeMap.put(MifareUltralight.class.getName(), TagTechnology.MIFARE_ULTRALIGHT); techStringToCodeMap.put(Ndef.class.getName(), TagTechnology.NDEF); techStringToCodeMap.put(NdefFormatable.class.getName(), TagTechnology.NDEF_FORMATABLE); techStringToCodeMap.put(NfcA.class.getName(), TagTechnology.NFC_A); techStringToCodeMap.put(NfcB.class.getName(), TagTechnology.NFC_B); techStringToCodeMap.put(NfcF.class.getName(), TagTechnology.NFC_F); techStringToCodeMap.put(NfcV.class.getName(), TagTechnology.NFC_V); techStringToCodeMap.put(NfcBarcode.class.getName(), TagTechnology.NFC_BARCODE); return techStringToCodeMap; }
Example #3
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 #4
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 #5
Source File: EmvReadActivity.java From smartcard-reader with GNU General Public License v3.0 | 6 votes |
@Override public void onTagDiscovered(Tag tag) { doTapFeedback(); clearImage(); // maybe clear console or show separator, depends on settings if (mAutoClear) { clearMessages(); } else { addMessageSeparator(); } // get IsoDep handle and run xcvr thread IsoDep isoDep = IsoDep.get(tag); if (isoDep == null) { onError(getString(R.string.wrong_tag_err)); } else { ReaderXcvr xcvr = new PaymentReaderXcvr(isoDep, "", this, TEST_MODE_EMV_READ); new Thread(xcvr).start(); } }
Example #6
Source File: BatchSelectActivity.java From smartcard-reader with GNU General Public License v3.0 | 6 votes |
@Override public void onTagDiscovered(Tag tag) { doTapFeedback(); clearImage(); // maybe clear console or show separator, depends on settings if (mAutoClear) { clearMessages(); } else { // two separators between taps/discoveries addMessageSeparator(); addMessageSeparator(); } // get IsoDep handle and run xcvr thread IsoDep isoDep = IsoDep.get(tag); if (isoDep == null) { onError(getString(R.string.wrong_tag_err)); } else { List<SmartcardApp> memberApps = mGrpToMembersMap.get(mSelectedGrpPos); new Thread(new BatchReaderXcvr(isoDep, memberApps, this)).start(); } }
Example #7
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 #8
Source File: MainActivity.java From flutter-nfc-app with MIT License | 6 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GeneratedPluginRegistrant.registerWith(this); Log.i("", "onCreate"); mAdapter = NfcAdapter.getDefaultAdapter(this); if (mAdapter == null) { Log.i("", "mAdapter null"); } mPendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); mFilters = new IntentFilter[]{new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED)}; mTechLists = new String[][]{new String[]{IsoDep.class.getName()}}; new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler( new MethodChannel.MethodCallHandler() { @Override public void onMethodCall(MethodCall call, MethodChannel.Result result) { if (call.method.equals("getPlatformVersion")) { result.success("Android ${android.os.Build.VERSION.RELEASE}"); } else if (call.method.equals("getCardUID")) { result.success(getCardUID()); } else if (call.method.equals("getVersion")) { String commands = call.argument("commands"); result.success(getVersion(commands)); } else { result.notImplemented(); } } }); }
Example #9
Source File: BatchReaderXcvr.java From smartcard-reader with GNU General Public License v3.0 | 5 votes |
public BatchReaderXcvr(IsoDep isoDep, List<SmartcardApp> apps, ReaderXcvr.UiCallbacks uiCallbacks) { mIsoDep = isoDep; mApps = apps; mUiCallbacks = uiCallbacks; mContext = (Context) uiCallbacks; mSize = apps.size(); mIndex = 0; }
Example #10
Source File: ReaderXcvr.java From smartcard-reader with GNU General Public License v3.0 | 5 votes |
public ReaderXcvr(IsoDep isoDep, String aid, UiCallbacks uiCallbacks) { this.mIsoDep = isoDep; this.mAid = aid; this.mAidBytes = Util.hexToBytes(aid); this.mUiCallbacks = uiCallbacks; this.mContext = (Context) uiCallbacks; }
Example #11
Source File: TagDispatcher.java From WalletCordova with GNU Lesser General Public License v2.1 | 5 votes |
private void enableForegroundDispatch(NfcAdapter adapter, Intent intent) { if(adapter.isEnabled()) { PendingIntent tagIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); IntentFilter tag = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); adapter.enableForegroundDispatch(activity, tagIntent, new IntentFilter[]{tag}, new String[][]{new String[]{IsoDep.class.getName()}}); } }
Example #12
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 #13
Source File: ReaderXcvr.java From smartcard-reader with GNU General Public License v3.0 | 5 votes |
public ReaderXcvr(IsoDep isoDep, String aid, UiCallbacks uiCallbacks, Context context) { this.mIsoDep = isoDep; this.mAid = aid; this.mAidBytes = Util.hexToBytes(aid); this.mUiCallbacks = uiCallbacks; this.mContext = context; }
Example #14
Source File: NfcBankomatCardReader.java From bankomatinfos with GNU General Public License v3.0 | 5 votes |
/** * Connects to IsoDep * * @throws IOException */ public void connectIsoDep() throws IOException, NoSmartCardException { _localIsoDep = IsoDep.get(_nfcTag); if (_localIsoDep == null) { throw new NoSmartCardException("This NFC tag is no ISO 7816 card"); } _localIsoDep.connect(); }
Example #15
Source File: AppSelectActivity.java From smartcard-reader with GNU General Public License v3.0 | 5 votes |
@Override public void onTagDiscovered(Tag tag) { doTapFeedback(); clearImage(); // maybe clear console or show separator, depends on settings if (mAutoClear) { clearMessages(); } else { addMessageSeparator(); } // get IsoDep handle and run xcvr thread IsoDep isoDep = IsoDep.get(tag); if (isoDep == null) { onError(getString(R.string.wrong_tag_err)); } else { ReaderXcvr xcvr; String aid = mApps.get(mSelectedAppPos).getAid(); if (mManual) { runOnUiThread(new Runnable() { @Override public void run() { Animation shake = AnimationUtils.loadAnimation(AppSelectActivity.this, R.anim.shake); mSelectButton.startAnimation(shake); } }); // manual select mode; for multiple selects per tap/connect // does not select ppse for payment apps unless specifically configured xcvr = new ManualReaderXcvr(isoDep, aid, this); } else if (mApps.get(mSelectedAppPos).getType() == SmartcardApp.TYPE_PAYMENT) { // payment, ie. always selects ppse first xcvr = new PaymentReaderXcvr(isoDep, aid, this, TEST_MODE_APP_SELECT); } else { // other/non-payment; auto select on each tap/connect xcvr = new OtherReaderXcvr(isoDep, aid, this); } new Thread(xcvr).start(); } }
Example #16
Source File: StandardPboc.java From NFCard with GNU General Public License v3.0 | 5 votes |
public static void readCard(IsoDep tech, Card card) throws InstantiationException, IllegalAccessException, IOException { final Iso7816.StdTag tag = new Iso7816.StdTag(tech); tag.connect(); for (final Class<?> g[] : readers) { HINT hint = HINT.RESETANDGONEXT; for (final Class<?> r : g) { final StandardPboc reader = (StandardPboc) r.newInstance(); switch (hint) { case RESETANDGONEXT: if (!reader.resetTag(tag)) continue; case GONEXT: hint = reader.readCard(tag, card); break; default: break; } if (hint == HINT.STOP) break; } } tag.close(); }
Example #17
Source File: MainActivity.java From host-card-emulation-sample with MIT License | 5 votes |
@Override public void onTagDiscovered(Tag tag) { IsoDep isoDep = IsoDep.get(tag); IsoDepTransceiver transceiver = new IsoDepTransceiver(isoDep, this); Thread thread = new Thread(transceiver); thread.start(); }
Example #18
Source File: StandardPboc.java From nfcard with GNU General Public License v3.0 | 5 votes |
public static void readCard(IsoDep tech, Card card) throws InstantiationException, IllegalAccessException, IOException { final Iso7816.StdTag tag = new Iso7816.StdTag(tech); tag.connect(); for (final Class<?> g[] : readers) { HINT hint = HINT.RESETANDGONEXT; for (final Class<?> r : g) { final StandardPboc reader = (StandardPboc) r.newInstance(); switch (hint) { case RESETANDGONEXT: if (!reader.resetTag(tag)) continue; case GONEXT: hint = reader.readCard(tag, card); break; default: break; } if (hint == HINT.STOP) break; } } tag.close(); }
Example #19
Source File: TagDispatcher.java From nordpol with MIT License | 5 votes |
private void enableForegroundDispatch(NfcAdapter adapter, Intent intent) { if(adapter.isEnabled()) { PendingIntent tagIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); IntentFilter tag = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); adapter.enableForegroundDispatch(activity, tagIntent, new IntentFilter[]{tag}, new String[][]{new String[]{IsoDep.class.getName()}}); } }
Example #20
Source File: MainActivity.java From flutter-nfc-app with MIT License | 5 votes |
@SuppressLint("MissingPermission") @TargetApi(Build.VERSION_CODES.KITKAT) private void setIsoDep(Intent intent) { try { Log.i("","setIsoDep entered"); if (intent == null) { Log.i("","intent null"); return; } Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); if (tag == null) { Log.i("","tag null"); return; } isoDep = IsoDep.get(tag); if (isoDep != null && !isoDep.isConnected()) { isoDep.connect(); Log.i("","isodep connect ok"); } else { Log.i("","isodep null or connect not ok"); } } catch (Exception e) { Log.e("","",e); } }
Example #21
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; }
Example #22
Source File: NfcManager.java From nfcspy with GNU General Public License v3.0 | 5 votes |
static void disconnect(IsoDep tag) { try { if (tag != null) tag.close(); } catch (Exception e) { } }
Example #23
Source File: NfcManager.java From nfcspy with GNU General Public License v3.0 | 5 votes |
static String getCardId(IsoDep isodep) { if (isodep != null) { byte[] id = isodep.getTag().getId(); if (id != null && id.length > 0) return Logger.toHexString(id, 0, id.length); } return "UNKNOWN"; }
Example #24
Source File: TagDispatcher.java From GreenBits with GNU General Public License v3.0 | 5 votes |
private void enableForegroundDispatch(NfcAdapter adapter, Intent intent) { if(adapter.isEnabled()) { PendingIntent tagIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); IntentFilter tag = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); adapter.enableForegroundDispatch(activity, tagIntent, new IntentFilter[]{tag}, new String[][]{new String[]{IsoDep.class.getName()}}); } }
Example #25
Source File: PassportConnection.java From polling-station-app with GNU Lesser General Public License v3.0 | 5 votes |
/** * Opens a connection with the ID by doing BAC * Uses hardcoded parameters for now * * @param tag - NFC tag that started this activity (ID NFC tag) * @return PassportService - passportservice that has an open connection with the ID */ public PassportService openConnection(Tag tag, final DocumentData docData) throws CardServiceException { try { IsoDep nfc = IsoDep.get(tag); CardService cs = CardService.getInstance(nfc); this.ps = new PassportService(cs); this.ps.open(); // Get the information needed for BAC from the data provided by OCR this.ps.sendSelectApplet(false); BACKeySpec bacKey = new BACKeySpec() { @Override public String getDocumentNumber() { return docData.getDocumentNumber(); } @Override public String getDateOfBirth() { return docData.getDateOfBirth(); } @Override public String getDateOfExpiry() { return docData.getExpiryDate(); } }; ps.doBAC(bacKey); return ps; } catch (CardServiceException ex) { try { ps.close(); } catch (Exception ex2) { ex2.printStackTrace(); } throw ex; } }
Example #26
Source File: ManualReaderXcvr.java From smartcard-reader with GNU General Public License v3.0 | 4 votes |
public ManualReaderXcvr(IsoDep isoDep, String aid, UiCallbacks uiCallbacks) { super(isoDep, aid, uiCallbacks); }
Example #27
Source File: OtherReaderXcvr.java From smartcard-reader with GNU General Public License v3.0 | 4 votes |
public OtherReaderXcvr(IsoDep isoDep, String aid, UiCallbacks uiCallbacks, Context context) { super(isoDep, aid, uiCallbacks, context); }
Example #28
Source File: OtherReaderXcvr.java From smartcard-reader with GNU General Public License v3.0 | 4 votes |
public OtherReaderXcvr(IsoDep isoDep, String aid, UiCallbacks uiCallbacks) { super(isoDep, aid, uiCallbacks); }
Example #29
Source File: Tag.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private String[] generateTechStringList(int[] techList) { final int size = techList.length; String[] strings = new String[size]; for (int i = 0; i < size; i++) { switch (techList[i]) { case TagTechnology.ISO_DEP: strings[i] = IsoDep.class.getName(); break; case TagTechnology.MIFARE_CLASSIC: strings[i] = MifareClassic.class.getName(); break; case TagTechnology.MIFARE_ULTRALIGHT: strings[i] = MifareUltralight.class.getName(); break; case TagTechnology.NDEF: strings[i] = Ndef.class.getName(); break; case TagTechnology.NDEF_FORMATABLE: strings[i] = NdefFormatable.class.getName(); break; case TagTechnology.NFC_A: strings[i] = NfcA.class.getName(); break; case TagTechnology.NFC_B: strings[i] = NfcB.class.getName(); break; case TagTechnology.NFC_F: strings[i] = NfcF.class.getName(); break; case TagTechnology.NFC_V: strings[i] = NfcV.class.getName(); break; case TagTechnology.NFC_BARCODE: strings[i] = NfcBarcode.class.getName(); break; default: throw new IllegalArgumentException("Unknown tech type " + techList[i]); } } return strings; }
Example #30
Source File: DesfireProtocol.java From MensaGuthaben with GNU General Public License v3.0 | 4 votes |
public DesfireProtocol(IsoDep tagTech) { mTagTech = tagTech; }