Example usage for android.nfc.tech MifareClassic KEY_DEFAULT

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

Introduction

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

Prototype

null KEY_DEFAULT

To view the source code for android.nfc.tech MifareClassic KEY_DEFAULT.

Click Source Link

Document

The default factory key.

Usage

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   ww  w .  j  a v a  2s .  c  o  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();
        }
    }
}