Filtering tags by their technology
There are several types of NFC tags. They mostly differ on the storage capacity and on the communication standard used. In our application, we may want to use only a specific type of tag because of a certain characteristic of that specific tag. The Android SDK supports the most frequent tag types such as MIFARE Classic and MIFARE Ultralight tags.
How to do it...
We will create an application that is executed only when the tag technology matches the one specified by us:
Open Eclipse and create a new Android application project named
NfcBookCh2Example3
with the package namenfcbook.ch2.example3
.Open the
MainActivity.java
file, override theonNewIntent
method, and insert the following code:@Override protected void onNewIntent(Intent intent) { if ( isNfcIntent(intent) ) { Toast.makeText( this, "NFC intent received", Toast.LENGTH_SHORT).show(); } }
Implement the
isNfcIntent
method:boolean isNfcIntent(Intent intent) { return intent.hasExtra...