get String As Ndef from NFC - Android Network

Android examples for Network:NFC Ndef

Description

get String As Ndef from NFC

Demo Code


//package com.java2s;

import android.nfc.NdefMessage;
import android.nfc.NdefRecord;

public class Main {
    public static NdefMessage getStringAsNdef(short tnf, String type,
            String id, String payload) {
        byte[] idBytes = id.getBytes();
        byte[] payloadBytes = payload.getBytes();
        byte[] typeBytes = type.getBytes();
        NdefRecord textRecord = new NdefRecord(tnf, typeBytes, idBytes,
                payloadBytes);/*from   w  ww  .  j a v  a  2s. c  om*/
        return new NdefMessage(new NdefRecord[] { textRecord });
    }
}

Related Tutorials