I am working on Near Field Communication for reading data from NFC Tags.
I don’t have NFC supported Android Mobile and NFC Tags to test the Application i created .
I want to know whether it is possible to Launch my App through intent filter(Should assume NFC tag is detected from my device)
My Manifest Snippet :
<activity
android:name=".ServerActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="abc.com"
android:pathPrefix="/aaap"
android:scheme="http" />
</intent-filter>
</activity>
My Activity Snippet :
@Override
protected void onNewIntent(Intent intent) {
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
Toast.makeText(getApplicationContext(), "ACTION_TAG_DISCOVERED",
Toast.LENGTH_LONG);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}
}
After some research on NFC i found that we can read/write NFC Tags without NFC enabled device.. But answer is so simple.. It’s nothing but playing with Intents :
We have to call this snippet for invoking NFC :
Also we should register our Activity to Android System through Manifest file like below :
Manifest.xml
Same way if you have more than one Activity using same action we will be getting chooser from which we can launch our Desired Activity.
Receiving inside Activity :
TagViewer .java
We have this sample in Developer Sample Demo.