hamena314
hamena314

Reputation: 3109

Reading the contents of a NFC Tag

I am trying to read an NFC Tag on a Samsung Galaxy Nexus S.

    @Override
protected void onResume() {
    super.onResume();
    String nachricht = "";
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        Parcelable[] rawMsgs = getIntent()
                .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (rawMsgs != null) {
            NdefMessage[] msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
                nachricht = nachricht + " " + msgs;
            }

            Log.e("WriteTagApp", nachricht );
        }
    }

}

With Log.e("WriteTagApp", nachricht ); my app writes the message of the tag into the Debugger. It looks something like this: [Landroid.nfc.NdefMessage;@4184ce18

I dont seem to be able to understand what is going on here and how to get the actual content of the message. How do I do that?

Upvotes: 1

Views: 1368

Answers (1)

Alexander Lucas
Alexander Lucas

Reputation: 22371

NDefMessage isn't a String, it's an object. By concatonating it you're just adding the output of its "toString" method. Instead, you need to look at the NdefRecords inside the NdefMessage and pull the data from the payload field in there.

Upvotes: 1

Related Questions