Android examples for Network:NFC Message
get Ndef Messages from Intent
//package com.java2s; import android.content.Intent; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.NfcAdapter; import android.os.Parcelable; import android.util.Log; public class Main { private static final String TAG = "NfcUtils"; public static NdefMessage[] getNdefMessages(Intent intent) { // Parse the intent NdefMessage[] msgs = null;// www. java 2 s .c om String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { Parcelable[] rawMsgs = intent .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } else { // Unknown tag type byte[] empty = new byte[] {}; NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty); NdefMessage msg = new NdefMessage( new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } } else { Log.d(TAG, "Unknown intent."); } return msgs; } }