dump NdefMessages, logs the contents of an array of ndef messages. - Android Network

Android examples for Network:NFC Message

Description

dump NdefMessages, logs the contents of an array of ndef messages.

Demo Code

//    CheckIn4Me is free software: you can redistribute it and/or modify
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Parcelable;
import android.util.Log;

public class Main{
    private static final String TAG = NFCUtils.class.getName();
    /**//from www. ja  v  a  2 s .c  o m
     * 
     * logs the contents of an array of ndef messages.
     * 
     * @param msgs
     */
    public static void dumpNdefMessages(NdefMessage[] msgs) {
        Log.i(TAG, "number of ndef messages = " + msgs.length);

        for (int i = 0; i < msgs.length; i++) {
            NdefRecord[] records = msgs[i].getRecords();
            Log.i(TAG, "number of records = " + records.length);

            for (int j = 0; j < records.length; j++) {
                String id = new String(records[j].getId());
                String type = new String(records[j].getType());
                String payload = new String(records[j].getPayload());

                Log.i(TAG, "record number " + (j + 1));
                Log.i(TAG, "id = " + id);
                Log.i(TAG, "type = " + type);
                Log.i(TAG, "payload = " + payload);
            }
        }
    }
}

Related Tutorials