NFC Programming in Android Ishan Fernando @ifdo [email_address] Myti s.r.l. www.myti.it
NFC (Near Field Communication) E' una tecnologia wireless a corto raggio (< 10cm)
NFC (Near Field Communication) Si opera alla frequenza di 13,56MHz Può raggiungere una velocità di trasmissione  massima di 424 kbit/s.
NFC (Near Field Communication) E' una evoluzione di RFID (Radio Frequency Identification)
Storia
NDEF (NFC Data Exchange Format) NDEF è un formato di incapsulamento dei messaggi (dati) per scambiare informazioni via NFC.
NDEF (NFC Data Exchange Format) Questo formato consente di scambiare informazioni  tra due NFC Forum Devices  tra un NFC Forum Device e un NFC Forum Tag.
NDEF (NFC Data Exchange Format) Message  = n * Records Records  =  Type + Size +  Payload (binary data)
NDEF (NFC Data Exchange Format) I messaggi  NDEF  possono essere di tre tipi :  URI   il contenuto è un link MIME   il contenuto è specificato da un mime type NFC-specific types  utilizzi specifici per diverse tecnologie http://www.nfc-forum.org/specs/spec_list/
NFC e NDEF summary NDEF  è un formato di encapsulamento dei dati NFC  è una tecnologia wireless a corto raggio che consente di creare una comunicazione bidirezionale
NFC Technology summary NFC Wireless a corto raggio (< 10cm) Frequenza : 13,56MHz  Velocità di trasmissione massima : 424 Kbit/s.   E' una evoluzione di RFID NDEF Incapsulamento dei messaggi NFC Forum Device <=> NFC Forum Device  NFC Forum Device <=> NFC Forum Tag Message = n * Records Records = Type + Size + Payload (binary data) Types: URI, MIME o NFC-specific types
NFC e Android
NFC e Android - dispatch system Maggior parte delle APIs sono basate su NDEF The tag dispatch system
Intent e Foreground Dispatch Systems Intent Dispatch System dichiara i filtri nel Manifest, fa partire l'applicazione anche se è spenta. Foreground Dispatch System dichiara i filtri mentre in esecuzione, gestione esclusiva per i tag richiesti.
Discover NDEF Tag - Permessi <uses-permission          android:name = &quot;android.permission.NFC&quot;   /> <uses-sdk            android:minSdkVersion = &quot;10&quot; /> <uses-feature            android:name = &quot;android.hardware.nfc&quot;           android:required = &quot;true&quot;   />
Discover NDEF Tag - Intent filter <activity>    ...    <intent-filter>      <action            android:name = &quot;android.nfc.action.NDEF_DISCOVERED&quot; />      <category            android:name = &quot;android.intent.category.DEFAULT&quot; />      <data            android:mimeType = &quot;text/plain&quot;   />    </intent-filter>    ... </activity>
NDEF Tag - Reading public   class  MyNFCActivity  extends  Activity  {      @ Override     public   void  onNewIntent ( Intent intent )   {        Parcelable []  raw  =  intent . getParcelableArrayExtra (                  NfcAdapter . EXTRA_NDEF_MESSAGES ) ;      NdefMessage message  =   ( NdefMessage )  raw [ 0 ] ;        NdefRecord record  =  message . getRecords ()[ 0 ] ;        byte []  payload  =  record . getPayload () ;        ...    } }
NDEF Tag - Writing public   class  MyNFCActivity  extends  Activity  {    @ Override    public   void  onNewIntent ( Intent intent )   {      Tag t  =  intent . getParcelableExtra ( NfcAdapter . EXTRA_TAG ) ;      Ndef ndef  =  Ndef . get (  t  ) ;      ndef . connect () ;      final   byte []  data  =  … ;      NdefRecord record  =   new  NdefRecord (              NdefRecord . TNF_MIME_MEDIA ,              &quot;text/plain&quot; . getBytes (),              new   byte [ 0 ],              data ) ;      NdefRecord []  records =  new  NdefRecord [] { record };      NdefMessage message  =   new  NdefMessage (  records  ) ;          ndef . writeNdefMessage ( message ) ;    } }
NFC e Android summary Dispatch systems Intent Dispatch System Foreground Dispatch System Permessi Intent Filter Lettura di un tag NDEF Scrittura di un tag NDEF
Safeatwork Sicurezza sul lavoro e supporto alla certificazione Usato dai manutentori e operai specializzati Backend web per la gestione dei dati Nata su j2me nel 2008 ( Nokia 6212 ) www.safeatwork.it
Safeatwork Download contenuti  Schede tecniche Istruzioni operative Accesso ai contenuti basato su NFC Upload delle attività cosa ha fatto l'operatore? che procedure ha eseguito?
Safeatwork L'interazione prevede prevalentemente l'utilizzo della lettura dei tag per accedere ai contenuti.
Grazie Android NFC developer documentation http://developer.android.com/guide/topics/nfc/ Nfc Forum http://www.nfc-forum.org/home/ Myti www.myti.it Ishan Fernando @ifdo [email_address]

GTUG NFC Presentation

  • 1.
    NFC Programming inAndroid Ishan Fernando @ifdo [email_address] Myti s.r.l. www.myti.it
  • 2.
    NFC (Near Field Communication)E' una tecnologia wireless a corto raggio (< 10cm)
  • 3.
    NFC (Near Field Communication)Si opera alla frequenza di 13,56MHz Può raggiungere una velocità di trasmissione  massima di 424 kbit/s.
  • 4.
    NFC (Near Field Communication)E' una evoluzione di RFID (Radio Frequency Identification)
  • 5.
  • 6.
    NDEF (NFC DataExchange Format) NDEF è un formato di incapsulamento dei messaggi (dati) per scambiare informazioni via NFC.
  • 7.
    NDEF (NFC DataExchange Format) Questo formato consente di scambiare informazioni  tra due NFC Forum Devices  tra un NFC Forum Device e un NFC Forum Tag.
  • 8.
    NDEF (NFC DataExchange Format) Message = n * Records Records  =  Type + Size +  Payload (binary data)
  • 9.
    NDEF (NFC DataExchange Format) I messaggi NDEF possono essere di tre tipi :  URI   il contenuto è un link MIME   il contenuto è specificato da un mime type NFC-specific types  utilizzi specifici per diverse tecnologie http://www.nfc-forum.org/specs/spec_list/
  • 10.
    NFC e NDEFsummary NDEF è un formato di encapsulamento dei dati NFC è una tecnologia wireless a corto raggio che consente di creare una comunicazione bidirezionale
  • 11.
    NFC Technology summaryNFC Wireless a corto raggio (< 10cm) Frequenza : 13,56MHz  Velocità di trasmissione massima : 424 Kbit/s.   E' una evoluzione di RFID NDEF Incapsulamento dei messaggi NFC Forum Device <=> NFC Forum Device  NFC Forum Device <=> NFC Forum Tag Message = n * Records Records = Type + Size + Payload (binary data) Types: URI, MIME o NFC-specific types
  • 12.
  • 13.
    NFC e Android- dispatch system Maggior parte delle APIs sono basate su NDEF The tag dispatch system
  • 14.
    Intent e ForegroundDispatch Systems Intent Dispatch System dichiara i filtri nel Manifest, fa partire l'applicazione anche se è spenta. Foreground Dispatch System dichiara i filtri mentre in esecuzione, gestione esclusiva per i tag richiesti.
  • 15.
    Discover NDEF Tag- Permessi <uses-permission          android:name = &quot;android.permission.NFC&quot; /> <uses-sdk            android:minSdkVersion = &quot;10&quot; /> <uses-feature            android:name = &quot;android.hardware.nfc&quot;          android:required = &quot;true&quot;   />
  • 16.
    Discover NDEF Tag- Intent filter <activity>   ...   <intent-filter>      <action            android:name = &quot;android.nfc.action.NDEF_DISCOVERED&quot; />      <category            android:name = &quot;android.intent.category.DEFAULT&quot; />      <data            android:mimeType = &quot;text/plain&quot; />   </intent-filter>   ... </activity>
  • 17.
    NDEF Tag - Readingpublic class MyNFCActivity extends Activity {     @ Override    public void onNewIntent ( Intent intent ) {        Parcelable [] raw = intent . getParcelableArrayExtra (                  NfcAdapter . EXTRA_NDEF_MESSAGES ) ;      NdefMessage message = ( NdefMessage ) raw [ 0 ] ;        NdefRecord record = message . getRecords ()[ 0 ] ;        byte [] payload = record . getPayload () ;       ...   } }
  • 18.
    NDEF Tag - Writingpublic class MyNFCActivity extends Activity {   @ Override   public void onNewIntent ( Intent intent ) {      Tag t  =  intent . getParcelableExtra ( NfcAdapter . EXTRA_TAG ) ;      Ndef ndef = Ndef . get (  t  ) ;      ndef . connect () ;      final byte [] data = … ;      NdefRecord record = new NdefRecord (              NdefRecord . TNF_MIME_MEDIA ,              &quot;text/plain&quot; . getBytes (),              new byte [ 0 ],              data ) ;     NdefRecord []  records =  new  NdefRecord [] { record };      NdefMessage message = new NdefMessage (  records  ) ;          ndef . writeNdefMessage ( message ) ;   } }
  • 19.
    NFC e Androidsummary Dispatch systems Intent Dispatch System Foreground Dispatch System Permessi Intent Filter Lettura di un tag NDEF Scrittura di un tag NDEF
  • 20.
    Safeatwork Sicurezza sullavoro e supporto alla certificazione Usato dai manutentori e operai specializzati Backend web per la gestione dei dati Nata su j2me nel 2008 ( Nokia 6212 ) www.safeatwork.it
  • 21.
    Safeatwork Download contenuti Schede tecniche Istruzioni operative Accesso ai contenuti basato su NFC Upload delle attività cosa ha fatto l'operatore? che procedure ha eseguito?
  • 22.
    Safeatwork L'interazione prevedeprevalentemente l'utilizzo della lettura dei tag per accedere ai contenuti.
  • 23.
    Grazie Android NFCdeveloper documentation http://developer.android.com/guide/topics/nfc/ Nfc Forum http://www.nfc-forum.org/home/ Myti www.myti.it Ishan Fernando @ifdo [email_address]

Editor's Notes

  • #3 corto raggio per i pagamenti e la sicurezza
  • #4 lento rispetto a bluetooth
  • #5 differenza principale tra NFC e RFID è NFC permette di fare una comunicazione bidirezionale.
  • #8 tag nfc è diverso da rfid
  • #15 The intent dispatch system is to launch a program from scratch. For instance, you turn your phone on and hover it over a tag. The phone launches an intent, identifying it as a Mifare card. Your app has an intent dispatch for Mifare cards, so it is one of the apps that can be selected. If your intent dispatch is specific enough(compared to other apps), it will be the only app to select, and will run at that point. Foreground dispatch is used by your app while it is running. This way, your app won&apos;t be turned off if another app has a similar intent dispatch setup. Now with your app running, it can discover a tag and handle the intent over other apps on the phone, and the phone will not prompt you to select from a bunch of apps that have a similar intent dispatch.
  • #16 API level 9 only supports limited tag dispatch via  ACTION_TAG_DISCOVERED , and only gives access to NDEF messages via the  EXTRA_NDEF_MESSAGES  extra. No other tag properties or I/O operations are accessible. API level 10 includes comprehensive reader/writer support as well as foreground NDEF pushing, and API level 14 provides an easier way to push NDEF messages to other devices with Android Beam and extra convenience methods to create NDEF records.
  • #19 3-bit TNF (Type Name Format) field: Indicates how to interpret the type field EXTRA_TAG   (required): A   Tag   object representing the scanned tag. EXTRA_NDEF_MESSAGES   (optional): An array of NDEF messages parsed from the tag. This extra is mandatory on   intents.