get As NFC Ndef message from String - Android Network

Android examples for Network:NFC Message

Description

get As NFC Ndef message from String

Demo Code


//package com.java2s;

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

public class Main {
    public static NdefMessage getAsNdef(String msg) {
        byte[] textBytes = msg.getBytes();
        NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
                "application/vnd.serpro.nfcevents".getBytes(),
                new byte[] {}, textBytes);
        return new NdefMessage(new NdefRecord[] { textRecord });
    }// w  w  w. ja  v a 2  s  . c o m
}

Related Tutorials