returns a pending nfc intent as an array of ndef messages - Android Network

Android examples for Network:NFC Message

Description

returns a pending nfc intent as an array of ndef messages

Demo Code

//    CheckIn4Me is free software: you can redistribute it and/or modify
//package com.java2s;
import android.content.Intent;
import android.nfc.NdefMessage;

import android.nfc.NfcAdapter;
import android.os.Parcelable;

public class Main {
    /**/*  w w w .  j a v a2s . c  om*/
     * getNdefMessages
     * 
     * returns a pending nfc intent as an array of ndef messages
     * 
     * @param intent
     * @return
     */
    public static NdefMessage[] getNdefMessages(Intent intent) {
        NdefMessage[] msgs = null;

        Parcelable[] raw_msgs = intent
                .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);

        if (raw_msgs != null) {
            msgs = new NdefMessage[raw_msgs.length];

            for (int i = 0; i < raw_msgs.length; i++) {
                msgs[i] = (NdefMessage) raw_msgs[i];
            }
        } else {
            msgs = new NdefMessage[0];
        }

        return msgs;
    }
}

Related Tutorials