send Card, create NdefMessage - Android Network

Android examples for Network:NFC Message

Description

send Card, create NdefMessage

Demo Code


//package com.java2s;
import java.nio.charset.Charset;

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

public class Main {
    public static NdefMessage sendCard(String idCard) {
        NdefRecord[] records = null;/* w  ww. jav  a 2  s .  c  om*/
        records = new NdefRecord[1];
        records[0] = createMimeRecord(
                "application/vnd.efrei.asyria.m1a.smartcard.beam",
                idCard.getBytes());

        return new NdefMessage(records);
    }

    public static NdefRecord createMimeRecord(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;
    }
}

Related Tutorials