• Like
  • Save
Nfc on Android
Upcoming SlideShare
Loading in...5
×
 

Nfc on Android

on

  • 2,866 views

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

Statistics

Views

Total Views
2,866
Views on SlideShare
2,826
Embed Views
40

Actions

Likes
10
Downloads
4
Comments
1

5 Embeds 40

https://twitter.com 34
https://twimg0-a.akamaihd.net 2
http://twitter.com 2
https://si0.twimg.com 1
http://www.docshut.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • 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
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Nfc on Android Nfc on Android Presentation Transcript

    • A new world is coming… @fernando_cejas www.fernandocejas.com
    • Who am I?• Barcelona GDG Organizer• NFC, Android and Agile Geek• Android10.org• NFC Actions App• Flojack (@flomio)• @fernando_cejas• http://www.fernandocejas.com/
    • Agenda• What is NFC?• NFC Features and components• Common (and not) use cases• Android and NFC• Android NFC Development• Demo code• Faq
    • 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.
    • Near Field Communication Physical action, virtual reactionIn practice, NFC enables simple and safetwo-way interactions among electronicdevices within a close proximity.
    • 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
    • NFC Modes• Read and write tags• Peer-to-peer• Card emulationAndroid support: – Read and write (excellent support) – P2P (limited)
    • NFC Tags
    • How can NFC change the world?
    • 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
    • NFC Manager• NFCManager used to get the NFCAdapter• Boring• Shortcut for getSystemService(NFC_SERVICE)
    • NFC Adapter• The real thing• Control Foreground Dispatch and P2P (Android Beam)• Check if NFC is turned on
    • 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" />
    • NDEF Messages• NFC Data Exchange Format (NDEF)• NFC Forum Standard
    • NFC Android Dyspatch System
    • 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>
    • 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);
    • 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 });
    • 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
    • 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;}
    • Sample Application https://github.com/android10
    • Mobile OS support for NFC
    • Any questions?
    • Thanks!When you look at the dark side, careful you must be ... for the dark side looks back. @fernando_cejas www.fernandocejas.com