Example usage for android.nfc.tech MifareClassic get

List of usage examples for android.nfc.tech MifareClassic get

Introduction

In this page you can find the example usage for android.nfc.tech MifareClassic get.

Prototype

public static MifareClassic get(Tag tag) 

Source Link

Document

Get an instance of MifareClassic for the given tag.

Usage

From source file:se.anyro.nfc_reader.TagViewer.java

private String dumpTagData(Parcelable p) {
    StringBuilder sb = new StringBuilder();
    Tag tag = (Tag) p;/*from   ww w.  j a  v a  2 s.c  o  m*/
    byte[] id = tag.getId();
    sb.append("Tag ID (hex): ").append(getHex(id)).append("\n");
    sb.append("Tag ID (dec): ").append(getDec(id)).append("\n");
    sb.append("ID (reversed): ").append(getReversed(id)).append("\n");

    String prefix = "android.nfc.tech.";
    sb.append("Technologies: ");
    for (String tech : tag.getTechList()) {
        sb.append(tech.substring(prefix.length()));
        sb.append(", ");
    }
    sb.delete(sb.length() - 2, sb.length());
    for (String tech : tag.getTechList()) {
        if (tech.equals(MifareClassic.class.getName())) {
            sb.append('\n');
            MifareClassic mifareTag = MifareClassic.get(tag);
            String type = "Unknown";
            switch (mifareTag.getType()) {
            case MifareClassic.TYPE_CLASSIC:
                type = "Classic";
                break;
            case MifareClassic.TYPE_PLUS:
                type = "Plus";
                break;
            case MifareClassic.TYPE_PRO:
                type = "Pro";
                break;
            }
            sb.append("Mifare Classic type: ");
            sb.append(type);
            sb.append('\n');

            sb.append("Mifare size: ");
            sb.append(mifareTag.getSize() + " bytes");
            sb.append('\n');

            sb.append("Mifare sectors: ");
            sb.append(mifareTag.getSectorCount());
            sb.append('\n');

            sb.append("Mifare blocks: ");
            sb.append(mifareTag.getBlockCount());
        }

        if (tech.equals(MifareUltralight.class.getName())) {
            sb.append('\n');
            MifareUltralight mifareUlTag = MifareUltralight.get(tag);
            String type = "Unknown";
            switch (mifareUlTag.getType()) {
            case MifareUltralight.TYPE_ULTRALIGHT:
                type = "Ultralight";
                break;
            case MifareUltralight.TYPE_ULTRALIGHT_C:
                type = "Ultralight C";
                break;
            }
            sb.append("Mifare Ultralight type: ");
            sb.append(type);
        }
    }

    return sb.toString();
}

From source file:net.tjohns.badgescanner.ScanActivity.java

private void scanBadge() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(VIBRATION_DURATION);

    Intent intent = getIntent();//from www . ja va2 s  .co  m

    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
        Tag rawTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        MifareClassic tag = MifareClassic.get(rawTag);
        try {
            // Read from badge
            NfcConnection tagConnection = new NfcConnection(tag, MifareClassic.KEY_DEFAULT);
            mBadge = new Badge();
            mBadge.readFromTag(tagConnection);
            tagConnection.close();
        } catch (TagLostException e) {
            // TODO(trevorjohns): Convert to dialog
            Toast.makeText(this, "Tag lost", Toast.LENGTH_LONG);
            finish();
        } catch (IOException e) {
            // TODO(trevorjohns): Convert to dialog
            Toast.makeText(this, "IOExcpetion detected", Toast.LENGTH_LONG);
            e.printStackTrace();
            finish();
        }
    }
}

From source file:org.ounl.lifelonglearninghub.mediaplayer.cast.refplayer.NFCVideoBrowserActivity.java

/**
 * Returns text data for given parecelable 
 * /*from w  w  w .  jav a  2 s  .c  om*/
 * @param p
 * @return
 */
private String dumpTagData(Parcelable p) {
    Log.d(CLASSNAME, "dumpTagData is called Parcelable" + p);

    StringBuilder sb = new StringBuilder();
    Tag tag = (Tag) p;
    byte[] id = tag.getId();
    sb.append("Tag ID (hex): ").append(getHex(id)).append("\n");
    sb.append("Tag ID (dec): ").append(getDec(id)).append("\n");

    String prefix = "android.nfc.tech.";
    sb.append("Technologies: ");
    for (String tech : tag.getTechList()) {
        sb.append(tech.substring(prefix.length()));
        sb.append(", ");
    }
    sb.delete(sb.length() - 2, sb.length());
    for (String tech : tag.getTechList()) {
        if (tech.equals(MifareClassic.class.getName())) {
            sb.append('\n');
            MifareClassic mifareTag = MifareClassic.get(tag);
            String type = "Unknown";
            switch (mifareTag.getType()) {
            case MifareClassic.TYPE_CLASSIC:
                type = "Classic";
                break;
            case MifareClassic.TYPE_PLUS:
                type = "Plus";
                break;
            case MifareClassic.TYPE_PRO:
                type = "Pro";
                break;
            }
            sb.append("Mifare Classic type: ");
            sb.append(type);
            sb.append('\n');

            sb.append("Mifare size: ");
            sb.append(mifareTag.getSize() + " bytes");
            sb.append('\n');

            sb.append("Mifare sectors: ");
            sb.append(mifareTag.getSectorCount());
            sb.append('\n');

            sb.append("Mifare blocks: ");
            sb.append(mifareTag.getBlockCount());
        }

        if (tech.equals(MifareUltralight.class.getName())) {
            sb.append('\n');
            MifareUltralight mifareUlTag = MifareUltralight.get(tag);
            String type = "Unknown";
            switch (mifareUlTag.getType()) {
            case MifareUltralight.TYPE_ULTRALIGHT:
                type = "Ultralight";
                break;
            case MifareUltralight.TYPE_ULTRALIGHT_C:
                type = "Ultralight C";
                break;
            }
            sb.append("Mifare Ultralight type: ");
            sb.append(type);
        }
    }

    return sb.toString();
}