Converts a String into a NdefMessage in application - Android Network

Android examples for Network:NFC Message

Description

Converts a String into a NdefMessage in application

Demo Code


//package com.java2s;

import android.nfc.NdefRecord;

public class Main {
    /**/*from   ww w  .ja v  a 2s  .c  om*/
     * Converts a String into a NdefMessage in application/com.rivancic.nfc MIMEtype.
     */
    public static NdefRecord getMediaRecord(String messageToWrite,
            String type) {

        byte[] textBytes = messageToWrite.getBytes();
        NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
                type.getBytes(), new byte[] {}, textBytes);
        return textRecord;
    }
}

Related Tutorials