Your SlideShare is downloading. ×
Nfc on Android
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Nfc on Android

2,493
views

Published on

The sample app that demonstrates how to work with android and NFC technology is here: …

The sample app that demonstrates how to work with android and NFC technology is here:
https://github.com/android10

Published in: Technology

1 Comment
11 Likes
Statistics
Notes
  • hello Sir,nice presentation....but still i be Confused about Our(Software developer),what is our task in that type of nfc tasks like....chek this Sir
    'http://blog.laptopmag.com/top-5-nfc-apps-for-android-phones?slide=1'
    ........i am going to implement this in my final year project....reply me plz....
    email id: mohsin.afridi91@gmail.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
2,493
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
1
Likes
11
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. A new world is coming… @fernando_cejas www.fernandocejas.com
  • 2. Who am I?• Barcelona GDG Organizer• NFC, Android and Agile Geek• Android10.org• NFC Actions App• Flojack (@flomio)• @fernando_cejas• http://www.fernandocejas.com/
  • 3. Agenda• What is NFC?• NFC Features and components• Common (and not) use cases• Android and NFC• Android NFC Development• Demo code• Faq
  • 4. What is Near Field Communication?• Near Field Communication (NFC) is a global standard for short-range wireless connectivity technology• Driven by NFC Forum (http://www.nfc-forum.org) since 2004.• 160 + members, including Google, Intel, Microsoft, Nokia, NEC, Paypal, At&t, Visa, VTT.• Promote N-Mark trademark as a universal symbol for NFC.
  • 5. Near Field Communication Physical action, virtual reactionIn practice, NFC enables simple and safetwo-way interactions among electronicdevices within a close proximity.
  • 6. NFC Features• Short range technology – Connection established when devices or tag close enough (5-10 cm) – Simple setup (instant configuration)• 2-way communication – Not only reading like in contactless smart cards, but data exchange• Passive tags – No need for external power – Low-price• Security – Support secure element – Close proximity use brings some basic security
  • 7. NFC Modes• Read and write tags• Peer-to-peer• Card emulationAndroid support: – Read and write (excellent support) – P2P (limited)
  • 8. NFC Tags
  • 9. How can NFC change the world?
  • 10. NFC and Android• Tag Reading: since Android 2.3 – API level 9• Tag Writing: since Android 2.3.3 – API level 10• Beam (P2P): Android ICS 4.0 – API level 14Core Android classes: – NFC Manager – NFC Adapter – Tag Technology classes
  • 11. NFC Manager• NFCManager used to get the NFCAdapter• Boring• Shortcut for getSystemService(NFC_SERVICE)
  • 12. NFC Adapter• The real thing• Control Foreground Dispatch and P2P (Android Beam)• Check if NFC is turned on
  • 13. 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" />
  • 14. NDEF Messages• NFC Data Exchange Format (NDEF)• NFC Forum Standard
  • 15. NFC Android Dyspatch System
  • 16. Android ManifestIn AndroidManifest.xml (4.0+):<manifest ...> <uses-sdk android:minSdkVersion="10" /> <uses-feature android:name="android.hardware.nfc” android:required="true" /> <uses-permission android:name="android.permission.NFC" /> <application ...> <activity ...> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> //Could be custom </intent-filter> </activity> </application></manifest>
  • 17. Activity - Reacting to NFC scansIn the .java file for your Activity:import android.nfc.NfcAdapter;import android.nfc.NfcAdapter.CreateNdefMessageCallback;import android.nfc.NfcEvent;//...NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);Boolean nfcEnabled = mNfcAdapter.isEnabled();//Give priority to the foreground activity to receive NFC scan intents.mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mReadTagFilters, null);//Enable Android Beam for peer-to-peer mNfcAdapter.setNdefPushMessageCallback(this,this);
  • 18. Activity - Formatting to NDEF FormatIn the .java file for your Activity:import android.nfc.NdefMessage;import android.nfc.NdefRecord;import android.nfc.tech.Ndef;import android.nfc.tech.NdefFormatable;//...String data = “Hello NFC”;// create a new NDEF record w/ NDEF message using the apps custom MIME type:String mimeType = "application/root.gast.playground.nfc"; //unique to your appbyte[] mimeBytes = mimeType.getBytes(Charset.forName("UTF-8"));byte[] dataBytes = data.getBytes(Charset.forName("UTF-8"));byte[] id = new byte[0];NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, id, dataBytes);NdefMessage m = new NdefMessage(new NdefRecord[] { record });
  • 19. Activity - Reading NDEF FormatIn the .java file for your Activity: import android.nfc.Tag;//...Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);NdefMessage[] msgs = new NdefMessage[rawMsgs.length];for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i];}NdefRecord record = msgs[0].getRecords()[0];byte[] payload = record.getPayload(); //the info you wanted
  • 20. Activity - Android BeamIn the .java file for your Activity://Implement the interfacepublic class BeamActivity extends Activity implements CreateNdefMessageCallback// Register callbackmNfcAdapter.setNdefPushMessageCallback(this, this);public NdefMessage createNdefMessage(NfcEvent event) { String data = "Hello NFC”; // create a new NDEF record and containing NDEF message: String mimeType = "application/com.fernandocejas.example.android.nfc”; byte[] mimeBytes = mimeType.getBytes(Charset.forName("UTF-8")); byte[] dataBytes = data.getBytes(Charset.forName("UTF-8")); byte[] id = new byte[0]; NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, id, dataBytes); NdefMessage message = new NdefMessage(new NdefRecord[] { record }); return message;}
  • 21. Sample Application https://github.com/android10
  • 22. Mobile OS support for NFC
  • 23. Any questions?
  • 24. Thanks!When you look at the dark side, careful you must be ... for the dark side looks back. @fernando_cejas www.fernandocejas.com