Android examples for Network:NFC Message
Creates an Ndef message for NFC
//package com.java2s; import java.nio.charset.Charset; import android.nfc.NdefMessage; import android.nfc.NdefRecord; public class Main { /**/*w ww. j a v a2s. c o m*/ * Creates an Ndef message * * @param payload * @return */ public static NdefMessage createMessage(String mimeType, byte[] payload) { // Min API Level of 14 requires an array as the argument return new NdefMessage(new NdefRecord[] { createRecord(mimeType, payload) }); } /** * Creates a custom MIME type encapsulated in an NDEF record for a given * payload * * @param mimeType */ public static NdefRecord createRecord(String mimeType, byte[] payload) { byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII")); NdefRecord mimeRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload); return mimeRecord; } }