Whymca nfc presentation
-
Upload
myti-srl -
Category
Technology
-
view
1.299 -
download
3
description
Transcript of Whymca nfc presentation
![Page 1: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/1.jpg)
NFC Programming in Android
Ishan Fernando@ifdo
Myti@myti_newswww.myti.it
![Page 2: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/2.jpg)
NFC
• Comunicazione contactless• Nuova interazione utente • Sicurezza
![Page 3: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/3.jpg)
NFC (Near Field Communication)
![Page 4: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/4.jpg)
NFC (Near Field Communication)
• E' una tecnologia wireless a corto raggio (< 10cm)• Si opera alla frequenza di 13,56MHz• Può raggiungere una velocità di trasmissione massima di
424 kbit/s
![Page 5: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/5.jpg)
RFID to NFC
E' una evoluzione di RFID (Radio Frequency Identification)
![Page 6: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/6.jpg)
RFID vs NFC
RFID NFC
estenzione di RFID
distanze lunghe (3 ~ 100m) distanze corte (< 10cm)
qualsiasi frequenza 13.56 MHz
usa nei vari ambiti usa nell’ambito di sicurezza
nei celluari
![Page 7: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/7.jpg)
Storia
![Page 8: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/8.jpg)
NDEF (NFC Data Exchange Format)
NDEF è un formato di incapsulamento dei messaggi (dati) per scambiare informazioni via NFC.
![Page 9: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/9.jpg)
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.
active modepassive mode
![Page 10: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/10.jpg)
NDEF (NFC Data Exchange Format)
Message = n * Records
Records = Type +Size +
Payload (binary data)
![Page 11: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/11.jpg)
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/
![Page 12: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/12.jpg)
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
![Page 13: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/13.jpg)
NFC Technology summary
• NFCoWireless a corto raggio (< 10cm)o Frequenza : 13,56MHz oVelocità di trasmissione massima : 424 Kbit/s.o E' una evoluzione di RFID
• NDEFo Incapsulamento dei messaggioNFC Forum Device <=> NFC Forum Device oNFC Forum Device <=> NFC Forum TagoMessage = n * RecordsoRecords = Type + Size + Payload (binary data)o Types: URI, MIME o NFC-specific types
![Page 14: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/14.jpg)
Android
![Page 15: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/15.jpg)
Android
![Page 16: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/16.jpg)
Android Application
Android Application
AndroidManifest.xml
Intents
Activities Services
Broadcast receivers Content providers
![Page 17: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/17.jpg)
AndroidManifest.xml
• L’applicazione deve dichiarare tutti i suoi componenti in questo file.
• Permessi, API level, caratteristiche hardware o software usate, altre libererie API.
<?xml version="1.0" encoding="utf-8"?><manifest ... > <application android:icon="@drawable/app_icon.png" ... > <activity android:name="com.example.project.ExampleActivity" android:label="@string/example_label" ... > </activity> ... </application></manifest>
![Page 18: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/18.jpg)
Activities
• Ogni Activity rappresenta un unico schermo con una interfaccia utente.
• Ognuna è indipendente dalle altre.• Un’Activity deve definire come main.• Ogni Activity puo far partire un’altra Activity.• Quando parte una nuova Activity quella precedente si
ferma e si conserva dentro uno Stack.• Per creare un Activity dobbiamo estendere classe astratto
Activity e suoi metodi.
![Page 19: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/19.jpg)
Intents
• Componenti di una applicazione (Activities, Services e Broadcast receivers) vengono attivati attraverso messaggi, chiamate Intents.
Component name
Action
Data
Category
Extra
Flags
Intent
![Page 20: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/20.jpg)
Intent Filters
• Explicit vs Implicit• Per definire quali Intents (impiciti) deve accettare un
componente.
![Page 21: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/21.jpg)
Communication
![Page 22: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/22.jpg)
Communication
![Page 23: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/23.jpg)
Summary
• AndroidManifest.xml definice tutti i componenti dell’applicazione.
• Ogni schermata dell’applicazione è un’Activity.• Intents sono i messaggi che avviano i componenti.• Usando Intents Filters si possono filtrare Intents non
desiderati.• Se ci sono operazioni lunghe che non richiedono
interfaccia utente si possono usare i Services.
![Page 24: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/24.jpg)
NFC e Android
![Page 25: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/25.jpg)
NFC e Android Summary
• Dichiarazione permessi, Intents e Intent filters in Manifest• Dispatch systems
o Intent Dispatch Systemo Foreground Dispatch System
• Codice: lettura di un tag NDEF• Codice: scrittura di un tag NDEF• Codice: Foreground dispatch system• Codice: Device to Device (Beam)
![Page 26: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/26.jpg)
AndroidManifest
• Dichiarazione Activities• Dichiarazione Intents• Dichiarazione Intent filters• Permessi• API level • Caratteristiche hardware
![Page 27: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/27.jpg)
...<activity> ... <intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="text/plain" />
</intent-filter> ...</activity>...
Discover NDEF Tag - Intent filter
![Page 28: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/28.jpg)
...<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="10"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />...
Discover NDEF Tag - Permessi
![Page 29: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/29.jpg)
NFC e Android - dispatch system• Maggior parte delle APIs sono basate su NDEF• The tag dispatch system
![Page 30: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/30.jpg)
NFC e Android - dispatch system• Maggior parte delle APIs sono basate su NDEF• The tag dispatch system
![Page 31: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/31.jpg)
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
![Page 32: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/32.jpg)
NDEF Tag - Reading
![Page 33: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/33.jpg)
public class MyNFCActivity extends Activity {
@Override public void onNewIntent(Intent intent) {
// 1. prendiamo il tag toccato dall’intent ricevuto Parcelable[] raw = intent.getParcelableArrayExtra(
NfcAdapter.EXTRA_NDEF_MESSAGES);
// 2. prendiamo il primo record del primo messaggio NdefMessage message = (NdefMessage) raw[0]; NdefRecord record = message.getRecords()[0];
// 3. leggiamo il payload del record byte[] payload = record.getPayload(); ...
}
}
NDEF Tag - Reading
![Page 34: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/34.jpg)
NDEF Tag - Writing
![Page 35: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/35.jpg)
public class MyNFCActivity extends Activity {
@Override public void onNewIntent(Intent intent) {
// 1. Creiamo una istanza di Ndef usando il tag ricevuto Tag t = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); Ndef ndef = Ndef.get( t ); ndef.connect();
// 2. Creiamo un record Ndef inserendo i nostri dati final byte[] data = …; NdefRecord record = new NdefRecord( NdefRecord.TNF_MIME_MEDIA, "text/plain".getBytes(), new byte[0], data);
// 3. Incapsuliamo il record dentro un messaggio Ndef NdefRecord[] records = new NdefRecord[]{record}; NdefMessage message = new NdefMessage( records ); ndef.writeNdefMessage(message); }}
NDEF Tag - Writing
![Page 36: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/36.jpg)
Foreground dispatch
Vuoi evitare la finestra di dialogo passando il tag direttamente alla tua applicazione?
![Page 37: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/37.jpg)
public void onCreate(Bundle savedInstanceState){
// 1. Creiamo un PendingIntent per dare al sistema per eseguire operazioni Intent i = new Intent(this, getClass()); i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); pendingIntent = PendingIntent.getActivity(this, 0, i, 0); // 2. Creiamo un filtro che accetta tutti i MIME types IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
ndef.addDataType("*/*");
// 3. Teniamo salvati i filtri e le technologie tag che l’applicazione vuole gestireintentFiltersArray = new IntentFilter[] {ndef};techListsArray = new String[][] { new String[]
{ NfcF.class.getName() } };
}
Foreground dispatch - create
![Page 38: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/38.jpg)
public class MyNFCActivity extends Activity {
@Override public void onResume() { super.onResume(); // 1. Abilitiamo quando l’Activity prende il controllo nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray);
}
@Override public void onPause() { super.onPause(); // 2. Disabilitiamo quando l’Activity perde il controllo nfcAdapter.disableForegroundDispatch(this);
}
@Override public void onNewIntent(Intent intent) { // 3. Usiamo l’Intent ricevuto allo stesso modo di Intent Dispatch System
}}
Foreground dispatch - enable/disable
![Page 39: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/39.jpg)
Device to Device
![Page 40: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/40.jpg)
Device to Device
• Scambiare dati tra due device Android.• Entrambi i dispositivi deve avere l’Activity in foreground e
schermo sbloccato.• Un messaggio NDEF alla volta.• Basta utilizzare uno dei metodi
– setNdefPushMessage() – setNdefPushMessageCallback()
![Page 41: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/41.jpg)
public class MyNFCActivity extends Activity {
@Overridepublic void onCreate(Bundle savedInstanceState) {
// 1. Creiamo un messaggio da spedireNdefMessage msg = new NdefMessage(...);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
// 2. Inseriamo il messaggio creato per spedire quando avvicina un devicenfcAdapter.setNdefPushMessage(msg, this);
}
}
Device to Device - setNdefPushMessage()
![Page 42: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/42.jpg)
public class MyNFCActivity extends Activity implements CreateNdefMessageCallback {
@Overridepublic void onCreate(Bundle savedInstanceState) {
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
// 1. Abilitiamo Beam passando un Activity (this)// ed una imeplementazione di CreateNdefMessageCallback (this)nfcAdapter.setNdefPushMessageCallback(this, this);
}
@Overridepublic NdefMessage createNdefMessage(NfcEvent event) {
// 2. Creiamo un messaggio da spedire quando parte la cominucazioneNdefMessage msg = new NdefMessage(...);return msg;
}}
Device to Device - setNdefPushMessageCallback()
![Page 43: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/43.jpg)
NFC e Android summary
• Dichiarazione permessi, Intents e Intent filters in Manifest• Dispatch systems
o Intent Dispatch Systemo Foreground Dispatch System
• Codice: lettura di un tag NDEF• Codice: scrittura di un tag NDEF• Codice: Foreground dispatch system• Codice: Device to Device (Beam)
![Page 44: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/44.jpg)
Android vs J2ME
Android J2ME
Intent lancia activity PushRegistry lancia midletP2P generic API P2P generic API
P2P attraverso messaggi NDEF
P2P come bytes
![Page 45: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/45.jpg)
![Page 46: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/46.jpg)
Safeatwork
Sicurezza sul lavoro e supporto alla certificazione
Usato dai manutentori e operai specializzatiBackend web per la gestione dei dati
Nata su j2me nel 2008( Nokia 6212 )
www.safeatwork.it
![Page 47: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/47.jpg)
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?
![Page 48: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/48.jpg)
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?
![Page 49: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/49.jpg)
SafeatworkL'interazione prevede prevalentemente l'utilizzo della lettura dei tag per accedere ai contenuti.
![Page 50: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/50.jpg)
SafeatworkL'interazione prevede prevalentemente l'utilizzo della lettura dei tag per accedere ai contenuti.
![Page 51: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/51.jpg)
Safeatwork in action
![Page 52: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/52.jpg)
Safeatwork in action
![Page 53: Whymca nfc presentation](https://reader034.fdocumenti.com/reader034/viewer/2022051610/5484c7695806b59f588b46c9/html5/thumbnails/53.jpg)
GrazieAndroid NFC developer documentationhttp://developer.android.com/guide/topics/nfc/
Nfc Forumhttp://www.nfc-forum.org/home/
Myti s.r.l.@myti_newswww.myti.it
Ishan [email protected]@myti.it