NFC on Android - Near Field Communication

Sven Haiges
Sven HaigesSoftware Developer um Yahoo!
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 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)
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
NFC on Android - Near Field Communication
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
• 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 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
                                                     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() } };
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 specifications 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 specifications 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 Definitions)

             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
1 von 57

Recomendados

Nfc Overview von
Nfc OverviewNfc Overview
Nfc Overviewmehdibs
3.9K views17 Folien
Near Field Communication by Mohammed Mudassir von
Near Field Communication by Mohammed MudassirNear Field Communication by Mohammed Mudassir
Near Field Communication by Mohammed MudassirMohammed Mudassir
6K views21 Folien
Emerging Technologies in Payment Industry von
Emerging Technologies in Payment IndustryEmerging Technologies in Payment Industry
Emerging Technologies in Payment IndustryErfan Moradian
4.5K views91 Folien
NFC: Shaping the Future of the Connected Customer Experience von
NFC: Shaping the Future of the Connected Customer ExperienceNFC: Shaping the Future of the Connected Customer Experience
NFC: Shaping the Future of the Connected Customer ExperienceNFC Forum
6.6K views29 Folien
VISIONFC - an NFC Forum event: NFC Payment & beyond presentations von
VISIONFC - an NFC Forum event: NFC Payment & beyond presentationsVISIONFC - an NFC Forum event: NFC Payment & beyond presentations
VISIONFC - an NFC Forum event: NFC Payment & beyond presentationsNFC Forum
1.3K views32 Folien
Co Je A Bude Nfc Jan Nemec Gemalto von
Co Je A Bude Nfc Jan Nemec GemaltoCo Je A Bude Nfc Jan Nemec Gemalto
Co Je A Bude Nfc Jan Nemec GemaltoTUESDAY Business Network
3.3K views25 Folien

Más contenido relacionado

Was ist angesagt?

Product manager for dynamic nfc id 11949 von
Product manager for dynamic nfc  id 11949Product manager for dynamic nfc  id 11949
Product manager for dynamic nfc id 11949Raoul Brouns
2.6K views3 Folien
Nokia NFC Presentation von
Nokia NFC PresentationNokia NFC Presentation
Nokia NFC Presentationmomobeijing
3K views28 Folien
Merchant360 SP4G(tm) NFC Coverage Walls Counters and Floors von
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 FloorsMerchant360, Inc.
2.9K views5 Folien
NFC wallet von
NFC walletNFC wallet
NFC walletKaterina Kovarskaya
451 views14 Folien
Nfc von
NfcNfc
NfcRobin Dabur
6.9K views25 Folien
The User Experience of Near Field Communication von
The User Experience of Near Field CommunicationThe User Experience of Near Field Communication
The User Experience of Near Field CommunicationMemi Beltrame
14.3K views80 Folien

Was ist angesagt?(20)

Product manager for dynamic nfc id 11949 von Raoul Brouns
Product manager for dynamic nfc  id 11949Product manager for dynamic nfc  id 11949
Product manager for dynamic nfc id 11949
Raoul Brouns2.6K views
Nokia NFC Presentation von momobeijing
Nokia NFC PresentationNokia NFC Presentation
Nokia NFC Presentation
momobeijing3K views
Merchant360 SP4G(tm) NFC Coverage Walls Counters and Floors von Merchant360, Inc.
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
Merchant360, Inc.2.9K views
The User Experience of Near Field Communication von Memi Beltrame
The User Experience of Near Field CommunicationThe User Experience of Near Field Communication
The User Experience of Near Field Communication
Memi Beltrame14.3K views
Contactless NFC Tags For Mobile Loyalty von Merchant360, Inc.
Contactless NFC Tags For Mobile LoyaltyContactless NFC Tags For Mobile Loyalty
Contactless NFC Tags For Mobile Loyalty
Merchant360, Inc.13.1K views
Telecommunications in the logistic sector lodz von Justino Lourenço
Telecommunications in the logistic sector lodzTelecommunications in the logistic sector lodz
Telecommunications in the logistic sector lodz
Justino Lourenço1.7K views
near field communication von Nitish Tanwar
near field communicationnear field communication
near field communication
Nitish Tanwar5.6K views
Near Field Communication on iPhone with iCarte von Andrew Roughan
Near Field Communication on iPhone with iCarteNear Field Communication on iPhone with iCarte
Near Field Communication on iPhone with iCarte
Andrew Roughan4.2K views
NFC in direct mail: The pros and cons von CPS Cards
NFC in direct mail: The pros and consNFC in direct mail: The pros and cons
NFC in direct mail: The pros and cons
CPS Cards5.4K views
Leverage RFID with NFC for Better ROI - by Steve McRae von Merchant360, Inc.
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
Merchant360, Inc.5.1K views
Vodafone Cash Service - NFC tag von Deyaa Ahmed
Vodafone Cash Service - NFC tagVodafone Cash Service - NFC tag
Vodafone Cash Service - NFC tag
Deyaa Ahmed4.9K views
Near Field Communication in m-Commerce von ThejasK8
Near Field Communication in m-CommerceNear Field Communication in m-Commerce
Near Field Communication in m-Commerce
ThejasK83.4K views
Designing low costs sensor system for the Internet of Things von Andreas Schaller
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 Schaller3.1K views

Destacado

Near field communication (nfc) technology von
Near field communication (nfc) technologyNear field communication (nfc) technology
Near field communication (nfc) technologyAnkur Sharma
50.3K views13 Folien
NFC technical presentation von
NFC technical presentationNFC technical presentation
NFC technical presentationAkshat Rohatgi
91.4K views23 Folien
NFC Technology von
NFC TechnologyNFC Technology
NFC TechnologyNeha Singh
38.2K views22 Folien
NFC Everywhere Brochure 2016 von
NFC Everywhere Brochure 2016NFC Everywhere Brochure 2016
NFC Everywhere Brochure 2016Laurent Dardé
6.3K views36 Folien
NFC(Near Field Communication) von
NFC(Near Field Communication)NFC(Near Field Communication)
NFC(Near Field Communication)ADARSH KUMAR
18.5K views25 Folien
Nfc kdr von
Nfc kdrNfc kdr
Nfc kdrShahul Hameed
10.5K views24 Folien

Destacado(20)

Near field communication (nfc) technology von Ankur Sharma
Near field communication (nfc) technologyNear field communication (nfc) technology
Near field communication (nfc) technology
Ankur Sharma50.3K views
NFC technical presentation von Akshat Rohatgi
NFC technical presentationNFC technical presentation
NFC technical presentation
Akshat Rohatgi91.4K views
NFC Technology von Neha Singh
NFC TechnologyNFC Technology
NFC Technology
Neha Singh38.2K views
NFC Everywhere Brochure 2016 von Laurent Dardé
NFC Everywhere Brochure 2016NFC Everywhere Brochure 2016
NFC Everywhere Brochure 2016
Laurent Dardé6.3K views
NFC(Near Field Communication) von ADARSH KUMAR
NFC(Near Field Communication)NFC(Near Field Communication)
NFC(Near Field Communication)
ADARSH KUMAR18.5K views
On Relaying NFC Payment Transactions using Android devices von cgvwzq
On Relaying NFC Payment Transactions using Android devicesOn Relaying NFC Payment Transactions using Android devices
On Relaying NFC Payment Transactions using Android devices
cgvwzq24.8K views
Near Field Communication (NFC) von Seminar Links
Near Field Communication (NFC)Near Field Communication (NFC)
Near Field Communication (NFC)
Seminar Links34.3K views
Tap into NFC Meetup - Boston von NFC Forum
Tap into NFC Meetup  - Boston Tap into NFC Meetup  - Boston
Tap into NFC Meetup - Boston
NFC Forum17.5K views
NEAR FIELD COMMUNICATION von Harisankar U K
NEAR FIELD COMMUNICATIONNEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATION
Harisankar U K106.4K views
Nfc tutorial von Roy Chen
Nfc tutorialNfc tutorial
Nfc tutorial
Roy Chen3.1K views
Guide du tag NFC : quels usages dans quels contextes ? von Olivier Devillers
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 ?
Olivier Devillers3.9K views
droidcon 2012: What's the Hack is NFC .., Hauke Meyn, NXP von Droidcon Berlin
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
Droidcon Berlin10.9K views
Near Field Communication (NFC Architecture and Operating Modes) von Deepak Kl
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 Kl17.6K views
Nfc-Full Presentation von DILIN RAJ DS
Nfc-Full PresentationNfc-Full Presentation
Nfc-Full Presentation
DILIN RAJ DS14.4K views
Near field communication von Nagesh Mishra
Near field communicationNear field communication
Near field communication
Nagesh Mishra13.4K views

Similar a NFC on Android - Near Field Communication

NFC & RFID on Android von
NFC & RFID on AndroidNFC & RFID on Android
NFC & RFID on Androidtodbotdotcom
118.7K views53 Folien
Nfc on Android von
Nfc on AndroidNfc on Android
Nfc on AndroidFernando Cejas
3.1K views24 Folien
Android NFC von
Android NFCAndroid NFC
Android NFCFrancesco Azzola
315 views6 Folien
NFC Bootcamp Seattle Day 2 von
NFC Bootcamp Seattle Day 2 NFC Bootcamp Seattle Day 2
NFC Bootcamp Seattle Day 2 traceebeebe
3.3K views32 Folien
DefCon 2012 - Near-Field Communication / RFID Hacking - Lee von
DefCon 2012 - Near-Field Communication / RFID Hacking - LeeDefCon 2012 - Near-Field Communication / RFID Hacking - Lee
DefCon 2012 - Near-Field Communication / RFID Hacking - LeeMichael Smith
2.6K views24 Folien
Near field communication von
Near field communicationNear field communication
Near field communicationParamvir Singh
4.5K views34 Folien

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

NFC & RFID on Android von todbotdotcom
NFC & RFID on AndroidNFC & RFID on Android
NFC & RFID on Android
todbotdotcom118.7K views
NFC Bootcamp Seattle Day 2 von traceebeebe
NFC Bootcamp Seattle Day 2 NFC Bootcamp Seattle Day 2
NFC Bootcamp Seattle Day 2
traceebeebe3.3K views
DefCon 2012 - Near-Field Communication / RFID Hacking - Lee von Michael Smith
DefCon 2012 - Near-Field Communication / RFID Hacking - LeeDefCon 2012 - Near-Field Communication / RFID Hacking - Lee
DefCon 2012 - Near-Field Communication / RFID Hacking - Lee
Michael Smith2.6K views
Architecture and Development of NFC Applications von Thomas de Lazzari
Architecture and Development of NFC ApplicationsArchitecture and Development of NFC Applications
Architecture and Development of NFC Applications
Thomas de Lazzari110.8K views
A 2018 practical guide to hacking RFID/NFC von Slawomir Jasek
A 2018 practical guide to hacking RFID/NFCA 2018 practical guide to hacking RFID/NFC
A 2018 practical guide to hacking RFID/NFC
Slawomir Jasek5.8K views
CONFidence 2018: A 2018 practical guide to hacking RFID/NFC (Sławomir Jasek) von PROIDEA
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)
PROIDEA104 views
A 2018 practical guide to hacking RFID/NFC von SecuRing
A 2018 practical guide to hacking RFID/NFCA 2018 practical guide to hacking RFID/NFC
A 2018 practical guide to hacking RFID/NFC
SecuRing16.4K views
Building a dApp on Tezos von TinaBregovi
Building a dApp on TezosBuilding a dApp on Tezos
Building a dApp on Tezos
TinaBregovi113 views
Encode x Tezos: Building a dApp on Tezos von KlaraOrban
Encode x Tezos: Building a dApp on TezosEncode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on Tezos
KlaraOrban153 views
Neal Thompson of Maritz at MPITechCon on RFID von Kyle Hillman
Neal Thompson of Maritz at MPITechCon on RFIDNeal Thompson of Maritz at MPITechCon on RFID
Neal Thompson of Maritz at MPITechCon on RFID
Kyle Hillman989 views
Outsmarting smartphones von SensePost
Outsmarting smartphonesOutsmarting smartphones
Outsmarting smartphones
SensePost901 views
Rfid101 rfid introduction_lr von Cecile Tan
Rfid101 rfid introduction_lrRfid101 rfid introduction_lr
Rfid101 rfid introduction_lr
Cecile Tan483 views
Rfid101 rfid introduction_lr von Cecile Tan
Rfid101 rfid introduction_lrRfid101 rfid introduction_lr
Rfid101 rfid introduction_lr
Cecile Tan769 views

Más de Sven Haiges

NFC and Commerce combined von
NFC and Commerce combinedNFC and Commerce combined
NFC and Commerce combinedSven Haiges
930 views29 Folien
End to End Realtime Communication using Mobiel Devices and the Web von
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 WebSven Haiges
704 views56 Folien
NFC Android Introduction von
NFC Android IntroductionNFC Android Introduction
NFC Android IntroductionSven Haiges
1.1K views53 Folien
Gesture-controlled web-apps von
Gesture-controlled web-appsGesture-controlled web-apps
Gesture-controlled web-appsSven Haiges
1.2K views27 Folien
CouchDB on Android von
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
5.4K views49 Folien
Android UI von
Android UIAndroid UI
Android UISven Haiges
3.3K views90 Folien

Más de Sven Haiges(11)

NFC and Commerce combined von Sven Haiges
NFC and Commerce combinedNFC and Commerce combined
NFC and Commerce combined
Sven Haiges930 views
End to End Realtime Communication using Mobiel Devices and the Web von Sven Haiges
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
Sven Haiges704 views
NFC Android Introduction von Sven Haiges
NFC Android IntroductionNFC Android Introduction
NFC Android Introduction
Sven Haiges1.1K views
Gesture-controlled web-apps von Sven Haiges
Gesture-controlled web-appsGesture-controlled web-apps
Gesture-controlled web-apps
Sven Haiges1.2K views
CouchDB on Android von Sven Haiges
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges5.4K views
Grails @ Java User Group Silicon Valley von Sven Haiges
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon Valley
Sven Haiges19K views
Grails and Dojo von Sven Haiges
Grails and DojoGrails and Dojo
Grails and Dojo
Sven Haiges3.1K views
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English von Sven Haiges
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Sven Haiges1.4K views
Grails 0.3-SNAPSHOT Presentation WJAX 2006 von Sven Haiges
Grails 0.3-SNAPSHOT Presentation WJAX 2006Grails 0.3-SNAPSHOT Presentation WJAX 2006
Grails 0.3-SNAPSHOT Presentation WJAX 2006
Sven Haiges972 views

Último

Five Things You SHOULD Know About Postman von
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
27 views43 Folien
Perth MeetUp November 2023 von
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023 Michael Price
15 views44 Folien
Future of Learning - Khoong Chan Meng von
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan MengNUS-ISS
33 views7 Folien
STPI OctaNE CoE Brochure.pdf von
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
12 views1 Folie
Future of Learning - Yap Aye Wee.pdf von
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdfNUS-ISS
41 views11 Folien
handbook for web 3 adoption.pdf von
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdfLiveplex
19 views16 Folien

Último(20)

Five Things You SHOULD Know About Postman von Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
Perth MeetUp November 2023 von Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
Future of Learning - Khoong Chan Meng von NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views
STPI OctaNE CoE Brochure.pdf von madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
Future of Learning - Yap Aye Wee.pdf von NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS41 views
handbook for web 3 adoption.pdf von Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex19 views
Spesifikasi Lengkap ASUS Vivobook Go 14 von Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
Black and White Modern Science Presentation.pptx von maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
The details of description: Techniques, tips, and tangents on alternative tex... von BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
Attacking IoT Devices from a Web Perspective - Linux Day von Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV von Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk88 views
Combining Orchestration and Choreography for a Clean Architecture von ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs169 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors von sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab15 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... von NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS28 views
.conf Go 2023 - Data analysis as a routine von Splunk
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routine
Splunk93 views

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 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!
  • 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
  • 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 • rfidshop.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 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
  • 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

Hinweis der Redaktion

  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