• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
NFC on Android - Near Field Communication
 

NFC on Android - Near Field Communication

on

  • 6,900 views

Introduces Near Field Communication, NFC Modes, Android APIs and mysterious NDEF Format (NDEFMessages, NDEFRecord, RTC, TNF, etc.)

Introduces Near Field Communication, NFC Modes, Android APIs and mysterious NDEF Format (NDEFMessages, NDEFRecord, RTC, TNF, etc.)

Statistics

Views

Total Views
6,900
Views on SlideShare
6,860
Embed Views
40

Actions

Likes
19
Downloads
0
Comments
7

7 Embeds 40

http://paper.li 23
http://twitter.com 6
http://www.linkedin.com 6
https://www.linkedin.com 2
https://twitter.com 1
http://us-w1.rockmelt.com 1
http://www.search-results.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

17 of 7 previous next Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • good
    Are you sure you want to
    Your message goes here
    Processing…
  • Nice info
    Are you sure you want to
    Your message goes here
    Processing…
  • elaborate slides
    Are you sure you want to
    Your message goes here
    Processing…
  • can I have a copy of this slide please? I am a student & will use you as referrence. thanks
    Are you sure you want to
    Your message goes here
    Processing…
  • Maybe one more note: There is really cool support for 'Package Records' in Android 4. That means if you add such a Package Record to an NDEF Message and write it on a tag, then a device without the app installed will automatically forward to the android market for installation. Very sweet, solves the distribution problem!

    In earlier days you had to use a trick: instead of writing the info (id, etc) on the tag alone, you'd prefix it with a URL. The URL would be opened if the app was not installed, redirecting to the Android market if it was an Android phone. This trick might still be great if you target non-Android devices, too.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

NFC on Android - Near Field Communication NFC on Android - Near Field Communication Presentation Transcript

  • NFC
  • aboutSven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de
  • aboutSven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de NFC
  • Basics Card Emulation Reader/Writer P2P NFC TagTechnologiesTag NDEFDispatch APIs Android
  • Basics
  • 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
  • NFC• “transfer data at low speed, without security, over short distances”• ~10 centimeters, in reality less• 424 kBit/s• 13.56 MHz
  • NFC Devices• First mainstream Android smartphone: Nexus S• Common in new top Android phones• New RIM / Nokia devices• Apple iPhone?
  • Nokia 6131 • released 2006 • early 2007: iPhone! • J2ME Spec: JSR 257 Contactless Communication API • NFC is not new!
  • Forecast NFC handsets (k units)600000450000300000150000 0 2010 2011(e) 2012(e) 2013(e) 2014(e) 2015(e) Source:IHS iSuppli,compiled by Digitimes,May 2011
  • Payment
  • Tickets Coupons Smart PosterPayment
  • Tickets Coupons Smart PosterPayment Identity Keycard Personal ID
  • NFC Checkin Tickets Social CouponsGaming vCard Smart Poster Payment Identity Keycard Personal ID
  • NFC Checkin Tickets Social Coupons Gaming vCard Smart Poster Payment WiFiConnections Bluetooth Identity Keycard Personal ID
  • Transponder Format Technology/Capacity 13.56 Mhz Wristbands 125 Khz Cards LabelsSticker Keyfobs NFC Forum Tags Type 1-4
  • can be made read only!NFC Forum Type 2 Tag Mifare Ultralight - 64 bytes Mifare Ultralight C - 192 bytes
  • Mifare UltralightAll Surface Tag
  • Mifare UltralightAll Surface Tag Mifare Ultralight Paper Ticket
  • Mifare UltralightAll Surface Tag Mifare Ultralight Paper Ticket Mifare Ultralight Square Label
  • Mifare Ultralight All Surface Tag Mifare Ultralight Paper TicketMifare Classic Mifare UltralightKeyfob Square Label
  • Shops• tagage.net• rfidshop.com• smartcardfocus.com• and many more...
  • Comparing NFC Source:NFC Forum
  • NFC Modes
  • NFC Modes• Peer-to-Peer Mode• Reader/Writer Mode• Card Emulation Mode
  • Android NFC Support• Peer-to-Peer Mode: limited• Reader/Writer Mode: excellent support• Card Emulation Mode: no support
  • NFC & Android
  • NFC & Android• Tag-Reading ab Android 2.3, API Level 9• Tag-Writing ab Android 2.3.3, API Level 10• Core classes: NFCAdapter, NFCManager, Tag Technology Classes
  • Android Manifest• NFC Permission <uses-permission android:name="android.permission.NFC" />• API Level <uses-sdk android:minSdkVersion="10" />• NFC Feature <uses-feature android:name="android.hardware.nfc" android:required="true" />
  • Android Manifest<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.flavor.android.nfc" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MimeActivity" android:label="MIME"> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <data android:mimeType="application/json" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.NFC" /> <uses-sdk android:minSdkVersion="10" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /></manifest>
  • Android Manifest<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.flavor.android.nfc" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MimeActivity" android:label="MIME"> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <data android:mimeType="application/json" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.NFC" /> <uses-sdk android:minSdkVersion="10" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /></manifest>
  • Android Manifest<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.flavor.android.nfc" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MimeActivity" android:label="MIME"> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <data android:mimeType="application/json" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.NFC" /> <uses-sdk android:minSdkVersion="10" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /></manifest>
  • Android Manifest<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.flavor.android.nfc" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MimeActivity" android:label="MIME"> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <data android:mimeType="application/json" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.NFC" /> <uses-sdk android:minSdkVersion="10" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /></manifest>
  • NFCManager• NFCManager used to get the NFCAdapter• Boring• Shortcut for getSystemService(NFC_SERVICE)
  • NFCAdapter• the real thing• Control Foreground Dispatch and P2P NDEF Push• check if NFC is turned on
  • Checking for NFCif (!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) );}
  • Reading a Tag• Unlock phone, touch tag :-)• Most likely, the intent chooser will open
  • 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()
  • Foreground DispatchnfcAdapter.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 techsintent = 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() } };
  • Receiving a Tagpublic 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())); }}
  • Tag TechnologiesTag Technologies map totech specifications or topseudo-technologie orcapabilities like NDEF orNDEFFormatable TagTechnologyMifareClassic MifareUltralight NdefFormatable Ndef NfcA NfcB NfcF NfcV IsoDep
  • Tag TechnologiesTag Technologies map totech specifications or topseudo-technologie orcapabilities like NDEF orNDEFFormatable TagTechnologyMifareClassic MifareUltralight NdefFormatable Ndef NfcA NfcB NfcF NfcV IsoDep
  • NDEF• NFC Data Exchange Format• NFC Forum• Records can be MIME-type media, URIs or RTDs (Record Type Definitions) 1 *Ndef-Tag NdefMessage NdefRecord
  • NdefRecordTNF Type ID Payload
  • NdefRecord TNF Type ID Payload URI URI :-)NdefRecord WELL_KNOWN SMART_POSTER MIME TEXT
  • Reading Tag Content//r = NdefRecordif (r.getTnf() == NdefRecord.TNF_ABSOLUTE_URI) { b.append(String .format("TNF_ABSOLUTE_URI: type(%1$s), id(%2$s), payload(%3$s)n", new String(r.getType()), idBytes.toString(), new String(r.getPayload())));}else if (r.getTnf() == NdefRecord.TNF_MIME_MEDIA){ b.append(String .format("TNF_MIME_MEDIA: type(%1$s), id(%2$s), payload(%3$s)n", new String(r.getType()), idBytes.toString(), new String(r.getPayload())));}
  • Tag Dispatch
  • Tag Dispatch Foreground Activity Dispatch NDEF Data Dispatch: ACTION_NDEF_DISCOVEREDTag Technology Dispatch: ACTION_TECH_DISCOVERED Fall-back Dispatch: ACTION_TAG_DISCOVERED
  • Direct Start• Write custom NDEF MIME-type media messages• Use custom IntentFilter to bind to your messages
  • Writing NDEF MIMENdefMessage msg = NFCUtil.getNdefMimeMessage("application/json", "{"key":"value"}");Intent i = new Intent(this, WriteActivity.class);i.putExtra(WriteActivity.NDEF_MESSAGE, msg);startActivity(i);
  • Writing NDEF MIMENdefMessage msg = NFCUtil.getNdefMimeMessage("application/json", "{"key":"value"}");Intent i = new Intent(this, WriteActivity.class);i.putExtra(WriteActivity.NDEF_MESSAGE, msg);startActivity(i);
  • Writing NDEF MIMEprivate static NdefRecord getMimeRecord(String mimeType, String content) { NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeType.getBytes(), getRandomIdBytes(), content.getBytes()); return record;}
  • Writing NDEF MIMENdef ndef = Ndef.get(tag);if (ndef.isWritable() && ndef.getMaxSize() > this.msg.toByteArray().length){ ndef.connect(); ndef.writeNdefMessage(this.msg); ndef.close();}else //show toast?
  • 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)
  • aboutSven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de
  • aboutSven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de NFC