6. NFC roots: RFID
• RFID - Radio Frequency Identification
• 1983: First RFID patent granted
• Typical, well-known use-cases for RFID
animal identification, road taxes, libraries
• 2004: Nokia, Philips and Sony established
the NFC Forum
7. NFC
• “transfer data at low speed, without
security, over short distances”
• ~10 centimeters, in reality less
• 424 kBit/s
• 13.56 MHz
8. NFC Devices
• First mainstream Android
smartphone: Nexus S
• Common in new top
Android phones
• New RIM / Nokia devices
• Apple iPhone?
9. Nokia 6131
• released 2006
• early 2007: iPhone!
• J2ME Spec: JSR 257
Contactless Communication API
• NFC is not new!
36. NFCAdapter
• the real thing
• Control Foreground Dispatch and
P2P NDEF Push
• check if NFC is turned on
37. Checking for NFC
if (!getNFCAdapter().isEnabled())
{
Toast.makeText(getApplicationContext(),
"Please activate NFC and press back to return to the application!",
Toast.LENGTH_LONG).show();
startActivity(
new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)
);
}
38. Reading a Tag
• Unlock phone,
touch tag :-)
• Most likely, the
intent chooser will
open
39. Foreground Dispatch
• Foreground Activity may redirect all intents
related to tag, technology or NDEF
discovery to itself
• Getting all tags while activity is visible:
enable in onResume(), disable in onPause()
40. Foreground Dispatch
nfcAdapter.enableForegroundDispatch( techListsArray does not matter
activity, here, as ACTION_TECH_DISCOVERED
is not in intentFilters array. It can
pendingIntent, be null :-)
intentFiltersArray,
Most basic TAG-catch-all:
techListsArray); use ACTION_TAG_DISCOVERED in
filterList, no techs
intent = PendingIntent.getActivity(activity, 0,
new Intent(activity, activity.getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
ndef.addDataType("*/*");
intentFiltersArray = new IntentFilter[] { ndef };
techListsArray = new String[][] { new String[] { NfcA.class.getName() } };
41. Receiving a Tag
public void onNewIntent(Intent intent) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}
...
tag.getId() //returns id as byte[]
String techs[] = tag.getTechList();
for (String tech : techs) {
if (tech.equals("android.nfc.tech.Ndef"))
{
Ndef ndef = Ndef.get(tag);
ndef.getType()
ndef.getMaxSize()
ndef.canMakeReadOnly()
ndef.isWritable()
NFCUtil.printNdefMessageDetails(ndef.getCachedNdefMessage()));
}
}
42. Tag Technologies
Tag Technologies map to
tech specifications or to
pseudo-technologie or
capabilities like NDEF or
NDEFFormatable
TagTechnology
MifareClassic MifareUltralight NdefFormatable Ndef
NfcA NfcB NfcF NfcV
IsoDep
43. Tag Technologies
Tag Technologies map to
tech specifications or to
pseudo-technologie or
capabilities like NDEF or
NDEFFormatable
TagTechnology
MifareClassic MifareUltralight NdefFormatable Ndef
NfcA NfcB NfcF NfcV
IsoDep
44. NDEF
• NFC Data Exchange Format
• NFC Forum
• Records can be MIME-type media, URIs or
RTDs (Record Type Definitions)
1 *
Ndef-Tag NdefMessage NdefRecord
55. P2P: NDEF Push
• Create NDEF Message which is pushed to
another active device once the other
device is close
NfcAdapter.enableForegroundNdefPush(activity, ndefmessage)
NfcAdapter.disableForegroundNdefPush(activity)
56. about
Sven Haiges, hybris GmbH
Twitter @hansamann
Android, HTML5,
Groovy & Grails
sven.haiges@hybris.de
57. about
Sven Haiges, hybris GmbH
Twitter @hansamann
Android, HTML5,
Groovy & Grails
sven.haiges@hybris.de
NFC