Example usage for android.nfc NfcAdapter EXTRA_NDEF_MESSAGES

List of usage examples for android.nfc NfcAdapter EXTRA_NDEF_MESSAGES

Introduction

In this page you can find the example usage for android.nfc NfcAdapter EXTRA_NDEF_MESSAGES.

Prototype

String EXTRA_NDEF_MESSAGES

To view the source code for android.nfc NfcAdapter EXTRA_NDEF_MESSAGES.

Click Source Link

Document

Extra containing an array of NdefMessage present on the discovered tag.

This extra is mandatory for #ACTION_NDEF_DISCOVERED intents, and optional for #ACTION_TECH_DISCOVERED , and #ACTION_TAG_DISCOVERED intents.

When this extra is present there will always be at least one NdefMessage element.

Usage

From source file:net.lp.hivawareness.v4.HIVAwarenessActivity.java

/**
 * Parses the NDEF Message from the intent and prints to the TextView
 *//*from   w  w  w.  ja  v a2  s  . c o m*/
void processIntent(Intent intent) {
    Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    // only one message sent during the beam
    NdefMessage msg = (NdefMessage) rawMsgs[0];

    String data = new String(msg.getRecords()[0].getPayload());
    String[] parts = data.split("\\|");

    // record 0 contains the MIME type, record 1 is the AAR, if present
    Log.v("HIV", "old status " + caught + " " + data);

    double partnerInfected = Double.parseDouble(parts[0]);
    Gender partnerGender = Gender.valueOf(parts[1]);
    updateInfectionStatus(partnerInfected, partnerGender);

    if (!HIVAwarenessActivity.DEBUG)
        FlurryAgent.onEvent("touched");
    AnalyticsUtils.getInstance().trackGAEvent("HIVAwarenessActivity", "Touched",
            this.getLocalClassName() + ".ListClick", caught);

    Log.v("HIV", "new status " + caught);

    showDialog(SMOKING_DIALOG_ID);

}