SlideShare a Scribd company logo
1 of 57
NFC
about
Sven Haiges, hybris GmbH
  Twitter @hansamann

    Android, HTML5,
    Groovy & Grails


 sven.haiges@hybris.de
about
Sven Haiges, hybris GmbH
  Twitter @hansamann

    Android, HTML5,
    Groovy & Grails


 sven.haiges@hybris.de

                           NFC
Basics                    Card
                            Emulation
                     Reader/Writer
                            P2P



                   NFC
 TagTechnologies
Tag NDEF
Dispatch                 APIs
                         Android
Basics
NFC roots: RFID

ā€¢ RFID - Radio Frequency Identiļ¬cation
ā€¢ 1983: First RFID patent granted
ā€¢ Typical, well-known use-cases for RFID
  animal identiļ¬cation, 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)
600000

450000

300000

150000

     0
      2010   2011(e)    2012(e)        2013(e)               2014(e)                     2015(e)




                                                 Source:IHS iSuppli,compiled by Digitimes,May 2011
Payment
Tickets
      Coupons
           Smart Poster



Payment
Tickets
       Coupons
            Smart Poster



Payment

          Identity
     Keycard
               Personal ID
NFC Checkin
                             Tickets
   Social                 Coupons
Gaming     vCard               Smart Poster



                   Payment

                             Identity
                        Keycard
                                  Personal ID
NFC Checkin
                              Tickets
    Social                 Coupons
 Gaming     vCard               Smart Poster



                    Payment
      WiFi
Connections
     Bluetooth                Identity
                         Keycard
                                   Personal ID
Transponder
     Format          Technology/Capacity


                      13.56 Mhz
 Wristbands                  125 Khz
      Cards Labels
Sticker 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 Ultralight
All Surface Tag
Mifare Ultralight
All Surface Tag

                    Mifare Ultralight
                    Paper Ticket
Mifare Ultralight
All Surface Tag

                      Mifare Ultralight
                      Paper Ticket




  Mifare Ultralight
     Square Label
Mifare Ultralight
                 All Surface Tag

                                       Mifare Ultralight
                                       Paper Ticket




Mifare Classic
                   Mifare Ultralight
Keyfob
                      Square Label
Shops

ā€¢ tagage.net
ā€¢ rļ¬dshop.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 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)
    );
}
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 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
                                                     ļ¬lterList, 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() } };
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()));	 	
	   }
}
Tag Technologies
Tag Technologies map to
tech speciļ¬cations or to
pseudo-technologie or
capabilities like NDEF or
NDEFFormatable

                                      TagTechnology



MifareClassic               MifareUltralight   NdefFormatable   Ndef

       NfcA                      NfcB              NfcF         NfcV

                                                  IsoDep
Tag Technologies
Tag Technologies map to
tech speciļ¬cations or to
pseudo-technologie or
capabilities like NDEF or
NDEFFormatable

                                      TagTechnology



MifareClassic               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 Deļ¬nitions)

             1                 *
Ndef-Tag         NdefMessage       NdefRecord
NdefRecord
TNF    Type   ID   Payload
NdefRecord
         TNF    Type      ID        Payload




                          URI                 URI :-)


NdefRecord             WELL_KNOWN        SMART_POSTER


                         MIME                 TEXT
Reading Tag Content
//r = NdefRecord
if (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_DISCOVERED



Tag 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 MIME

NdefMessage msg =
   NFCUtil.getNdefMimeMessage("application/json", "{"key":"value"}");
Intent i = new Intent(this, WriteActivity.class);
i.putExtra(WriteActivity.NDEF_MESSAGE, msg);
startActivity(i);
Writing NDEF MIME

NdefMessage msg =
   NFCUtil.getNdefMimeMessage("application/json", "{"key":"value"}");
Intent i = new Intent(this, WriteActivity.class);
i.putExtra(WriteActivity.NDEF_MESSAGE, msg);
startActivity(i);
Writing NDEF MIME

private static NdefRecord getMimeRecord(String mimeType, String content) {
	   NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
	   	    	   mimeType.getBytes(), getRandomIdBytes(), content.getBytes());
	   return record;
}
Writing NDEF MIME
Ndef 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)
about
Sven Haiges, hybris GmbH
  Twitter @hansamann

    Android, HTML5,
    Groovy & Grails


 sven.haiges@hybris.de
about
Sven Haiges, hybris GmbH
  Twitter @hansamann

    Android, HTML5,
    Groovy & Grails


 sven.haiges@hybris.de

                           NFC

More Related Content

What's hot

Product manager for dynamic nfc id 11949
Product manager for dynamic nfc  id 11949Product manager for dynamic nfc  id 11949
Product manager for dynamic nfc id 11949
Raoul Brouns
Ā 
Nokia NFC Presentation
Nokia NFC PresentationNokia NFC Presentation
Nokia NFC Presentation
momobeijing
Ā 
near field communication
near field communicationnear field communication
near field communication
Nitish Tanwar
Ā 
Rfid and the Mobile phone quiz
Rfid and the Mobile phone quizRfid and the Mobile phone quiz
Rfid and the Mobile phone quiz
Theodor Tolstoy
Ā 
Designing low costs sensor system for the Internet of Things
Designing low costs sensor system for the Internet of ThingsDesigning low costs sensor system for the Internet of Things
Designing low costs sensor system for the Internet of Things
Andreas Schaller
Ā 
E-Catalogue Of HUAYUAN RFID Products
E-Catalogue Of HUAYUAN RFID ProductsE-Catalogue Of HUAYUAN RFID Products
E-Catalogue Of HUAYUAN RFID Products
HUAYUAN ELECTRONIC
Ā 

What's hot (20)

Product manager for dynamic nfc id 11949
Product manager for dynamic nfc  id 11949Product manager for dynamic nfc  id 11949
Product manager for dynamic nfc id 11949
Ā 
Nokia NFC Presentation
Nokia NFC PresentationNokia NFC Presentation
Nokia NFC Presentation
Ā 
Merchant360 SP4G(tm) NFC Coverage Walls Counters and Floors
Merchant360 SP4G(tm) NFC Coverage Walls Counters and FloorsMerchant360 SP4G(tm) NFC Coverage Walls Counters and Floors
Merchant360 SP4G(tm) NFC Coverage Walls Counters and Floors
Ā 
NFC wallet
NFC walletNFC wallet
NFC wallet
Ā 
Nfc
NfcNfc
Nfc
Ā 
The User Experience of Near Field Communication
The User Experience of Near Field CommunicationThe User Experience of Near Field Communication
The User Experience of Near Field Communication
Ā 
Contactless NFC Tags For Mobile Loyalty
Contactless NFC Tags For Mobile LoyaltyContactless NFC Tags For Mobile Loyalty
Contactless NFC Tags For Mobile Loyalty
Ā 
Telecommunications in the logistic sector lodz
Telecommunications in the logistic sector lodzTelecommunications in the logistic sector lodz
Telecommunications in the logistic sector lodz
Ā 
near field communication
near field communicationnear field communication
near field communication
Ā 
Near Field Communication on iPhone with iCarte
Near Field Communication on iPhone with iCarteNear Field Communication on iPhone with iCarte
Near Field Communication on iPhone with iCarte
Ā 
Rfid and the Mobile phone quiz
Rfid and the Mobile phone quizRfid and the Mobile phone quiz
Rfid and the Mobile phone quiz
Ā 
NFC in direct mail: The pros and cons
NFC in direct mail: The pros and consNFC in direct mail: The pros and cons
NFC in direct mail: The pros and cons
Ā 
Leverage RFID with NFC for Better ROI - by Steve McRae
Leverage RFID with NFC for Better ROI - by Steve McRaeLeverage RFID with NFC for Better ROI - by Steve McRae
Leverage RFID with NFC for Better ROI - by Steve McRae
Ā 
NFC Guidebook, 2011
NFC Guidebook, 2011NFC Guidebook, 2011
NFC Guidebook, 2011
Ā 
NFC Patents for Smartphone Mobile Payments Licensing Potential Assessment
NFC Patents for Smartphone Mobile Payments Licensing Potential AssessmentNFC Patents for Smartphone Mobile Payments Licensing Potential Assessment
NFC Patents for Smartphone Mobile Payments Licensing Potential Assessment
Ā 
Vodafone Cash Service - NFC tag
Vodafone Cash Service - NFC tagVodafone Cash Service - NFC tag
Vodafone Cash Service - NFC tag
Ā 
Civintec introduction 2015
Civintec introduction 2015Civintec introduction 2015
Civintec introduction 2015
Ā 
Near Field Communication in m-Commerce
Near Field Communication in m-CommerceNear Field Communication in m-Commerce
Near Field Communication in m-Commerce
Ā 
Designing low costs sensor system for the Internet of Things
Designing low costs sensor system for the Internet of ThingsDesigning low costs sensor system for the Internet of Things
Designing low costs sensor system for the Internet of Things
Ā 
E-Catalogue Of HUAYUAN RFID Products
E-Catalogue Of HUAYUAN RFID ProductsE-Catalogue Of HUAYUAN RFID Products
E-Catalogue Of HUAYUAN RFID Products
Ā 

Viewers also liked

NFC technical presentation
NFC technical presentationNFC technical presentation
NFC technical presentation
Akshat Rohatgi
Ā 
NFC Everywhere Brochure 2016
NFC Everywhere Brochure 2016NFC Everywhere Brochure 2016
NFC Everywhere Brochure 2016
Laurent DardƩ
Ā 
Near Field Communication (NFC Architecture and Operating Modes)
Near Field Communication (NFC Architecture and Operating Modes)Near Field Communication (NFC Architecture and Operating Modes)
Near Field Communication (NFC Architecture and Operating Modes)
Deepak Kl
Ā 
Near field communication
Near field communicationNear field communication
Near field communication
Nagesh Mishra
Ā 

Viewers also liked (20)

Near field communication (nfc) technology
Near field communication (nfc) technologyNear field communication (nfc) technology
Near field communication (nfc) technology
Ā 
NFC technical presentation
NFC technical presentationNFC technical presentation
NFC technical presentation
Ā 
NFC Technology
NFC TechnologyNFC Technology
NFC Technology
Ā 
NFC Everywhere Brochure 2016
NFC Everywhere Brochure 2016NFC Everywhere Brochure 2016
NFC Everywhere Brochure 2016
Ā 
NFC(Near Field Communication)
NFC(Near Field Communication)NFC(Near Field Communication)
NFC(Near Field Communication)
Ā 
Nfc kdr
Nfc kdrNfc kdr
Nfc kdr
Ā 
Nfc
NfcNfc
Nfc
Ā 
On Relaying NFC Payment Transactions using Android devices
On Relaying NFC Payment Transactions using Android devicesOn Relaying NFC Payment Transactions using Android devices
On Relaying NFC Payment Transactions using Android devices
Ā 
Near field communication
Near field communicationNear field communication
Near field communication
Ā 
Near Field Communication (NFC)
Near Field Communication (NFC)Near Field Communication (NFC)
Near Field Communication (NFC)
Ā 
Tap into NFC Meetup - Boston
Tap into NFC Meetup  - Boston Tap into NFC Meetup  - Boston
Tap into NFC Meetup - Boston
Ā 
NEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATIONNEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATION
Ā 
Nfc tutorial
Nfc tutorialNfc tutorial
Nfc tutorial
Ā 
Guide du tag NFC : quels usages dans quels contextes ?
Guide du tag NFC : quels usages dans quels contextes ?Guide du tag NFC : quels usages dans quels contextes ?
Guide du tag NFC : quels usages dans quels contextes ?
Ā 
droidcon 2012: What's the Hack is NFC .., Hauke Meyn, NXP
droidcon 2012: What's the Hack is NFC .., Hauke Meyn, NXPdroidcon 2012: What's the Hack is NFC .., Hauke Meyn, NXP
droidcon 2012: What's the Hack is NFC .., Hauke Meyn, NXP
Ā 
Near Field Communication (NFC Architecture and Operating Modes)
Near Field Communication (NFC Architecture and Operating Modes)Near Field Communication (NFC Architecture and Operating Modes)
Near Field Communication (NFC Architecture and Operating Modes)
Ā 
Nfc-Full Presentation
Nfc-Full PresentationNfc-Full Presentation
Nfc-Full Presentation
Ā 
Near field communication
Near field communicationNear field communication
Near field communication
Ā 
Nfc technology ppt
Nfc technology pptNfc technology ppt
Nfc technology ppt
Ā 
Near Field Communication & Android
Near Field Communication & AndroidNear Field Communication & Android
Near Field Communication & Android
Ā 

Similar to NFC on Android - Near Field Communication

DefCon 2012 - Near-Field Communication / RFID Hacking - Lee
DefCon 2012 - Near-Field Communication / RFID Hacking - LeeDefCon 2012 - Near-Field Communication / RFID Hacking - Lee
DefCon 2012 - Near-Field Communication / RFID Hacking - Lee
Michael Smith
Ā 
CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek)
CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek)CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek)
CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek)
PROIDEA
Ā 
Encode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on TezosEncode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on Tezos
KlaraOrban
Ā 
ABC2011Winter 惇éƒØ NFC
ABC2011Winter 惇éƒØ NFCABC2011Winter 惇éƒØ NFC
ABC2011Winter 惇éƒØ NFC
Masahiro Wakame
Ā 
Rfid101 rfid introduction_lr
Rfid101 rfid introduction_lrRfid101 rfid introduction_lr
Rfid101 rfid introduction_lr
Cecile Tan
Ā 
Rfid101 rfid introduction_lr
Rfid101 rfid introduction_lrRfid101 rfid introduction_lr
Rfid101 rfid introduction_lr
Cecile Tan
Ā 

Similar to NFC on Android - Near Field Communication (20)

NFC & RFID on Android
NFC & RFID on AndroidNFC & RFID on Android
NFC & RFID on Android
Ā 
Nfc on Android
Nfc on AndroidNfc on Android
Nfc on Android
Ā 
Android NFC
Android NFCAndroid NFC
Android NFC
Ā 
NFC Bootcamp Seattle Day 2
NFC Bootcamp Seattle Day 2 NFC Bootcamp Seattle Day 2
NFC Bootcamp Seattle Day 2
Ā 
DefCon 2012 - Near-Field Communication / RFID Hacking - Lee
DefCon 2012 - Near-Field Communication / RFID Hacking - LeeDefCon 2012 - Near-Field Communication / RFID Hacking - Lee
DefCon 2012 - Near-Field Communication / RFID Hacking - Lee
Ā 
Near field communication
Near field communicationNear field communication
Near field communication
Ā 
Architecture and Development of NFC Applications
Architecture and Development of NFC ApplicationsArchitecture and Development of NFC Applications
Architecture and Development of NFC Applications
Ā 
A 2018 practical guide to hacking RFID/NFC
A 2018 practical guide to hacking RFID/NFCA 2018 practical guide to hacking RFID/NFC
A 2018 practical guide to hacking RFID/NFC
Ā 
CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek)
CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek)CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek)
CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek)
Ā 
A 2018 practical guide to hacking RFID/NFC
A 2018 practical guide to hacking RFID/NFCA 2018 practical guide to hacking RFID/NFC
A 2018 practical guide to hacking RFID/NFC
Ā 
Encode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on TezosEncode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on Tezos
Ā 
Building a dApp on Tezos
Building a dApp on TezosBuilding a dApp on Tezos
Building a dApp on Tezos
Ā 
Neal Thompson of Maritz at MPITechCon on RFID
Neal Thompson of Maritz at MPITechCon on RFIDNeal Thompson of Maritz at MPITechCon on RFID
Neal Thompson of Maritz at MPITechCon on RFID
Ā 
Near field communication (NFC) in android
Near field communication (NFC) in androidNear field communication (NFC) in android
Near field communication (NFC) in android
Ā 
ABC2011Winter 惇éƒØ NFC
ABC2011Winter 惇éƒØ NFCABC2011Winter 惇éƒØ NFC
ABC2011Winter 惇éƒØ NFC
Ā 
Rto automation using nfc
Rto automation using nfcRto automation using nfc
Rto automation using nfc
Ā 
Aidc technology
Aidc technologyAidc technology
Aidc technology
Ā 
Outsmarting smartphones
Outsmarting smartphonesOutsmarting smartphones
Outsmarting smartphones
Ā 
Rfid101 rfid introduction_lr
Rfid101 rfid introduction_lrRfid101 rfid introduction_lr
Rfid101 rfid introduction_lr
Ā 
Rfid101 rfid introduction_lr
Rfid101 rfid introduction_lrRfid101 rfid introduction_lr
Rfid101 rfid introduction_lr
Ā 

More from Sven Haiges

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
Ā 
Android UI
Android UIAndroid UI
Android UI
Sven Haiges
Ā 

More from Sven Haiges (11)

NFC and Commerce combined
NFC and Commerce combinedNFC and Commerce combined
NFC and Commerce combined
Ā 
End to End Realtime Communication using Mobiel Devices and the Web
End to End Realtime Communication using Mobiel Devices and the WebEnd to End Realtime Communication using Mobiel Devices and the Web
End to End Realtime Communication using Mobiel Devices and the Web
Ā 
NFC Android Introduction
NFC Android IntroductionNFC Android Introduction
NFC Android Introduction
Ā 
Gesture-controlled web-apps
Gesture-controlled web-appsGesture-controlled web-apps
Gesture-controlled web-apps
Ā 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Ā 
Android UI
Android UIAndroid UI
Android UI
Ā 
Html5
Html5Html5
Html5
Ā 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon Valley
Ā 
Grails and Dojo
Grails and DojoGrails and Dojo
Grails and Dojo
Ā 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Ā 
Grails 0.3-SNAPSHOT Presentation WJAX 2006
Grails 0.3-SNAPSHOT Presentation WJAX 2006Grails 0.3-SNAPSHOT Presentation WJAX 2006
Grails 0.3-SNAPSHOT Presentation WJAX 2006
Ā 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(ā˜Žļø+971_581248768%)**%*]'#abortion pills for sale in dubai@
Ā 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
Ā 

Recently uploaded (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Ā 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Ā 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
Ā 
Scaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationScaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organization
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Ā 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Ā 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Ā 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
Ā 

NFC on Android - Near Field Communication

  • 1. NFC
  • 2. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de
  • 3. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de NFC
  • 4. Basics Card Emulation Reader/Writer P2P NFC TagTechnologies Tag NDEF Dispatch APIs Android
  • 6. NFC roots: RFID ā€¢ RFID - Radio Frequency Identiļ¬cation ā€¢ 1983: First RFID patent granted ā€¢ Typical, well-known use-cases for RFID animal identiļ¬cation, 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!
  • 10. Forecast NFC handsets (k units) 600000 450000 300000 150000 0 2010 2011(e) 2012(e) 2013(e) 2014(e) 2015(e) Source:IHS iSuppli,compiled by Digitimes,May 2011
  • 12. Tickets Coupons Smart Poster Payment
  • 13. Tickets Coupons Smart Poster Payment Identity Keycard Personal ID
  • 14. NFC Checkin Tickets Social Coupons Gaming vCard Smart Poster Payment Identity Keycard Personal ID
  • 15. NFC Checkin Tickets Social Coupons Gaming vCard Smart Poster Payment WiFi Connections Bluetooth Identity Keycard Personal ID
  • 16. Transponder Format Technology/Capacity 13.56 Mhz Wristbands 125 Khz Cards Labels Sticker Keyfobs NFC Forum Tags Type 1-4
  • 17. can be made read only! NFC Forum Type 2 Tag Mifare Ultralight - 64 bytes Mifare Ultralight C - 192 bytes
  • 18.
  • 20. Mifare Ultralight All Surface Tag Mifare Ultralight Paper Ticket
  • 21. Mifare Ultralight All Surface Tag Mifare Ultralight Paper Ticket Mifare Ultralight Square Label
  • 22. Mifare Ultralight All Surface Tag Mifare Ultralight Paper Ticket Mifare Classic Mifare Ultralight Keyfob Square Label
  • 23. Shops ā€¢ tagage.net ā€¢ rļ¬dshop.com ā€¢ smartcardfocus.com ā€¢ and many more...
  • 24. Comparing NFC Source:NFC Forum
  • 26. NFC Modes ā€¢ Peer-to-Peer Mode ā€¢ Reader/Writer Mode ā€¢ Card Emulation Mode
  • 27. Android NFC Support ā€¢ Peer-to-Peer Mode: limited ā€¢ Reader/Writer Mode: excellent support ā€¢ Card Emulation Mode: no support
  • 29. 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
  • 30. 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" />
  • 31. 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>
  • 32. 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>
  • 33. 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>
  • 34. 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>
  • 35. NFCManager ā€¢ NFCManager used to get the NFCAdapter ā€¢ Boring ā€¢ Shortcut for getSystemService(NFC_SERVICE)
  • 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 ļ¬lterList, 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 speciļ¬cations 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 speciļ¬cations 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 Deļ¬nitions) 1 * Ndef-Tag NdefMessage NdefRecord
  • 45. NdefRecord TNF Type ID Payload
  • 46. NdefRecord TNF Type ID Payload URI URI :-) NdefRecord WELL_KNOWN SMART_POSTER MIME TEXT
  • 47. Reading Tag Content //r = NdefRecord if (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()))); }
  • 49. Tag Dispatch Foreground Activity Dispatch NDEF Data Dispatch: ACTION_NDEF_DISCOVERED Tag Technology Dispatch: ACTION_TECH_DISCOVERED Fall-back Dispatch: ACTION_TAG_DISCOVERED
  • 50. Direct Start ā€¢ Write custom NDEF MIME-type media messages ā€¢ Use custom IntentFilter to bind to your messages
  • 51. Writing NDEF MIME NdefMessage msg = NFCUtil.getNdefMimeMessage("application/json", "{"key":"value"}"); Intent i = new Intent(this, WriteActivity.class); i.putExtra(WriteActivity.NDEF_MESSAGE, msg); startActivity(i);
  • 52. Writing NDEF MIME NdefMessage msg = NFCUtil.getNdefMimeMessage("application/json", "{"key":"value"}"); Intent i = new Intent(this, WriteActivity.class); i.putExtra(WriteActivity.NDEF_MESSAGE, msg); startActivity(i);
  • 53. Writing NDEF MIME private static NdefRecord getMimeRecord(String mimeType, String content) { NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeType.getBytes(), getRandomIdBytes(), content.getBytes()); return record; }
  • 54. Writing NDEF MIME Ndef ndef = Ndef.get(tag); if (ndef.isWritable() && ndef.getMaxSize() > this.msg.toByteArray().length) { ndef.connect(); ndef.writeNdefMessage(this.msg); ndef.close(); } else //show toast?
  • 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

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n