Filtering activities in the AndroidManifest.xml
file can really simplify our work and it allows us to define a more advanced filter than just the content type of a tag. In this recipe, we will learn how we can filter a URI tag.
By performing the following steps, we will create an application that is executed only when the URI parts present in the tags match our filters:
Open Eclipse and create a new Android application project named
NfcBookCh2Example5
with the package namenfcbook.ch2.example5
.Open
MainActivity
, 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(); } super.onNewIntent(intent); }
Implement the
isNfcIntent
method:boolean isNfcIntent(Intent intent) { return intent.hasExtra(NfcAdapter.EXTRA_TAG); }
Open the
AndroidManifest.xml
file and add the followingintent...