You are here

NFC for Android 2.3 through intents

Yesterday, Android 2.3 has been announced and it includes support for NFC Tag reading. The integration is quite easy because the NFC controller just starts the intent NfcAdapter.ACTION_TAG_DISCOVERED as soon as a tag is discovered.

In order to handle a discovered tag, add an intent filter for this action "android.nfc.action.TAG_DISCOVERED" and read the two extras from the intent like the following in your activity:

byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
NdefMessage[] msgs = (NdefMessage[]) intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);

Looking forward to new apps supporting NFC, please post them at http://open-android-apps.appspot.com if you like to share!