简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM