Showing posts with label NFC. Show all posts
Showing posts with label NFC. Show all posts

How to Register an Activity that Responds to NFC tags for URI's that point to a URL

This will register an Activity that will respond only to NFC tags that correspond to a URI that points a website (URL).
ACTION_NDEF_DISCOVERED(added in API level 10) is an Intent to start an activity when a tag with NDEF payload is discovered.

1. Add a new activity to your AndroidManifest.xml file. You may add it below  a closing (</activity) tag.

<activity android:name=".BlogViewer">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http:"
   android:host="androidsbs.blogspot.com"/>
</intent-filter>
</activity>

2. Compile and run!

Resources:Professional Android 4 Application Development by Reto Meier, pg 694
http://developer.android.com/reference/android/nfc/NfcAdapter.html#ACTION_NDEF_DISCOVERED

How to Set Permission for I/O Operations over NFC

public static final String NFC was added in API level 9
Allows applications to perform I/O operations over NFC

1. In the AndroidManifest.xml file, and add the following line Add the line between the <uses-sdk../> and the <application> tags.

<uses-permission android:name = "android.permission.NFC" />

2. Compile and run!