get Mime Record from NFC NdefRecord - Android Network

Android examples for Network:NFC Record

Description

get Mime Record from NFC NdefRecord

Demo Code


//package com.java2s;

import java.util.Random;

import android.nfc.NdefRecord;

public class Main {
    private static NdefRecord getMimeRecord(String mimeType, String content) {
        NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
                mimeType.getBytes(), getRandomIdBytes(), content.getBytes());
        return record;
    }//from   w w  w  .ja  v a  2 s.c o  m

    private static byte[] getRandomIdBytes() {
        Random rand = new Random(System.currentTimeMillis());
        byte buf[] = new byte[4];
        rand.nextBytes(buf);
        return buf;
    }
}

Related Tutorials