Example usage for android.nfc Tag getId

List of usage examples for android.nfc Tag getId

Introduction

In this page you can find the example usage for android.nfc Tag getId.

Prototype

public byte[] getId() 

Source Link

Document

Get the Tag Identifier (if it has one).

Usage

From source file:com.codebutler.farebot.TagReaderFactory.java

@NonNull
public TagReader getTagReader(@NonNull byte[] tagId, @NonNull Tag tag, @Nullable CardKeys cardKeys)
        throws UnsupportedTagException {
    String[] techs = tag.getTechList();
    if (ArrayUtils.contains(techs, "android.nfc.tech.IsoDep")) {
        return new DesfireTagReader(tagId, tag);
    } else if (ArrayUtils.contains(techs, "android.nfc.tech.NfcB")) {
        return new CEPASTagReader(tagId, tag);
    } else if (ArrayUtils.contains(techs, "android.nfc.tech.NfcF")) {
        return new FelicaTagReader(tagId, tag);
    } else if (ArrayUtils.contains(techs, "android.nfc.tech.MifareClassic")) {
        return new ClassicTagReader(tagId, tag, (ClassicCardKeys) cardKeys);
    } else if (ArrayUtils.contains(techs, "android.nfc.tech.MifareUltralight")) {
        return new UltralightTagReader(tagId, tag);
    } else {//from   w ww  .j  a  va 2 s. c o  m
        throw new UnsupportedTagException(techs, ByteUtils.getHexString(tag.getId()));
    }
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    String action = intent.getAction();

    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        // Get tag ID and turn into String
        byte[] tagIDbytes = tag.getId();
        tagID = bytesToHex(tagIDbytes);//from  w ww .j  a v  a2  s  . c  om

        if (!tagID.equals("")) {
            // Dismiss the 'Scan NFC Tag' dialog and show the 'Set tag name' dialog
            dismissDialog(DIALOG_READ);

            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

            MainActivity.this.showDialog(DIALOG_SET_TAGNAME);
        }
    }
}