Getting the data out of the message
In the previous recipe, we learn how to get NdefMessage
from the tag, but the actual data is in NdefRecords
present in the tag. In this recipe, we will see how to get the first NdefRecord
of NdefMessage
and how to get its content.
How to do it…
The following steps show how to get the data out of the message:
Open Eclipse and create a new Android application project named
NfcBookCh5Example2
and package namenfcbook.ch5.example2
.Make sure the
AndroidManifest.xml
file is correctly configured. Refer to the Requesting NFC permissions recipe in Chapter 1, Getting Started with NFC.Import the
NfcHelper
class into the project and enable the foreground dispatch system.Add the following class member and instantiate it in the
onCreate
method:private NfcHelper nfcHelper; protected void onCreate(Bundle savedInstanceState) { nfcHelper = new NfcHelper(this); ... }
Implement the
getFirstNdefRecord
method in theNfcHelper
class using the following code:public NdefRecord...