Example usage for android.nfc TagLostException printStackTrace

List of usage examples for android.nfc TagLostException printStackTrace

Introduction

In this page you can find the example usage for android.nfc TagLostException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

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();//w  w w .  j a v  a  2 s .c  om

    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();
        }
    }
}