Android examples for Network:NFC Ndef
get Int Array As Ndef from NFC
//package com.java2s; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.util.Log; public class Main { private static final String TAG = "NFCUtil"; public static NdefMessage getIntArrayAsNdef(short tnf, String type, String id, int[] payload, String delimiter) { byte[] idBytes = id.getBytes(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < payload.length - 1; i++) { sb.append(payload[i] + "-"); }/* w ww .j a va 2s . co m*/ sb.append(payload[payload.length - 1] + ""); Log.d(TAG, "Payload for ndefmsg = " + sb.toString()); byte[] payloadBytes = sb.toString().getBytes(); byte[] typeBytes = type.getBytes(); NdefRecord textRecord = new NdefRecord(tnf, typeBytes, idBytes, payloadBytes); return new NdefMessage(new NdefRecord[] { textRecord }); } public static NdefMessage getIntArrayAsNdef(short tnf, String type, String id, int[] payload, String delimiter, NdefRecord AAR) { byte[] idBytes = id.getBytes(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < payload.length - 1; i++) { sb.append(payload[i] + "-"); } sb.append(payload[payload.length - 1] + ""); Log.d(TAG, "Payload for ndefmsg = " + sb.toString()); byte[] payloadBytes = sb.toString().getBytes(); byte[] typeBytes = type.getBytes(); NdefRecord textRecord = new NdefRecord(tnf, typeBytes, idBytes, payloadBytes); return new NdefMessage(new NdefRecord[] { textRecord, AAR }); } }