SlideShare a Scribd company logo
1 of 24
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 reaction

In practice, NFC enables simple and safe
two-way interactions among electronic
devices 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 emulation

Android 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 14

Core 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 Manifest
In 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 scans

In 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 Format
In 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 app's custom MIME type:
String mimeType = "application/root.gast.playground.nfc"; //unique to your app
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 m = new NdefMessage(new NdefRecord[] { record });
Activity - Reading NDEF Format

In 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 Beam
In the .java file for your Activity:

//Implement the interface
public class BeamActivity extends Activity implements CreateNdefMessageCallback

// Register callback
mNfcAdapter.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

More Related Content

Viewers also liked

Neuro science and mystical experience
Neuro science and mystical experienceNeuro science and mystical experience
Neuro science and mystical experience
Joby Mathew
 
Bahaya narkoba kesehatan
Bahaya narkoba kesehatanBahaya narkoba kesehatan
Bahaya narkoba kesehatan
Rudy Irawan
 
Penyuluhan tentang bahaya penyalahgunaan narkotika
Penyuluhan tentang bahaya penyalahgunaan narkotikaPenyuluhan tentang bahaya penyalahgunaan narkotika
Penyuluhan tentang bahaya penyalahgunaan narkotika
Arif Kurniawan
 
presentasi penyalahgunaan narkoba
 presentasi penyalahgunaan narkoba presentasi penyalahgunaan narkoba
presentasi penyalahgunaan narkoba
Rinaldi Asertua
 

Viewers also liked (16)

Neuro science and mystical experience
Neuro science and mystical experienceNeuro science and mystical experience
Neuro science and mystical experience
 
Narkoba
NarkobaNarkoba
Narkoba
 
Bahaya narkoba kesehatan
Bahaya narkoba kesehatanBahaya narkoba kesehatan
Bahaya narkoba kesehatan
 
Penyuluhan tentang bahaya penyalahgunaan narkotika
Penyuluhan tentang bahaya penyalahgunaan narkotikaPenyuluhan tentang bahaya penyalahgunaan narkotika
Penyuluhan tentang bahaya penyalahgunaan narkotika
 
Persentasi narkoba
Persentasi narkobaPersentasi narkoba
Persentasi narkoba
 
NARKOBA
NARKOBANARKOBA
NARKOBA
 
Bluetooth Secure Simple Pairing Using NFC Part 2
Bluetooth Secure Simple Pairing Using NFC Part 2Bluetooth Secure Simple Pairing Using NFC Part 2
Bluetooth Secure Simple Pairing Using NFC Part 2
 
NFC In Mobile Commerce
NFC In Mobile CommerceNFC In Mobile Commerce
NFC In Mobile Commerce
 
presentasi keren bahaya narkoba
presentasi keren bahaya narkobapresentasi keren bahaya narkoba
presentasi keren bahaya narkoba
 
presentasi penyalahgunaan narkoba
 presentasi penyalahgunaan narkoba presentasi penyalahgunaan narkoba
presentasi penyalahgunaan narkoba
 
Contoh Presentasi Power Point Tentang Pendidikan
Contoh Presentasi Power Point Tentang PendidikanContoh Presentasi Power Point Tentang Pendidikan
Contoh Presentasi Power Point Tentang Pendidikan
 
Nfc ppt
Nfc pptNfc ppt
Nfc ppt
 
NFC Technology
NFC TechnologyNFC Technology
NFC Technology
 
Near field communication (nfc) technology
Near field communication (nfc) technologyNear field communication (nfc) technology
Near field communication (nfc) technology
 
NEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATIONNEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATION
 
NFC & RFID on Android
NFC & RFID on AndroidNFC & RFID on Android
NFC & RFID on Android
 

Similar to Nfc on Android

Wireless sensor networks using android virtual devices and near field
Wireless sensor networks using android virtual devices and near fieldWireless sensor networks using android virtual devices and near field
Wireless sensor networks using android virtual devices and near field
Nicolas Kockel
 
ABC2011Winter デ部 NFC
ABC2011Winter デ部 NFCABC2011Winter デ部 NFC
ABC2011Winter デ部 NFC
Masahiro Wakame
 
Near Field Communication (NFC Architecture and Operating Modes)
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 Kl
 

Similar to Nfc on Android (20)

NFC Bootcamp Seattle Day 2
NFC Bootcamp Seattle Day 2 NFC Bootcamp Seattle Day 2
NFC Bootcamp Seattle Day 2
 
Android NFC
Android NFCAndroid NFC
Android NFC
 
Wireless sensor networks using android virtual devices and near field
Wireless sensor networks using android virtual devices and near fieldWireless sensor networks using android virtual devices and near field
Wireless sensor networks using android virtual devices and near field
 
NFC on Android - Near Field Communication
NFC on Android - Near Field CommunicationNFC on Android - Near Field Communication
NFC on Android - Near Field Communication
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC Development
 
02 dev room6__tapand_go_jeffprosise_9Tap and Go: Proximity Networking in WinRT
02 dev room6__tapand_go_jeffprosise_9Tap and Go: Proximity Networking in WinRT02 dev room6__tapand_go_jeffprosise_9Tap and Go: Proximity Networking in WinRT
02 dev room6__tapand_go_jeffprosise_9Tap and Go: Proximity Networking in WinRT
 
Android Basic Presentation (Introduction)
Android Basic Presentation (Introduction)Android Basic Presentation (Introduction)
Android Basic Presentation (Introduction)
 
ABC2011Winter デ部 NFC
ABC2011Winter デ部 NFCABC2011Winter デ部 NFC
ABC2011Winter デ部 NFC
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Near Field Communication (NFC Architecture and Operating Modes)
Near Field Communication (NFC Architecture and Operating Modes)Near Field Communication (NFC Architecture and Operating Modes)
Near Field Communication (NFC Architecture and Operating Modes)
 
Developing NFC Apps
Developing NFC AppsDeveloping NFC Apps
Developing NFC Apps
 
Air superiority for Android Apps
Air superiority for Android AppsAir superiority for Android Apps
Air superiority for Android Apps
 
NFC (Windows 8/ Windows Phone 8 )
NFC (Windows 8/ Windows Phone 8 )NFC (Windows 8/ Windows Phone 8 )
NFC (Windows 8/ Windows Phone 8 )
 
NFiD: An NFC based system for Digital Business Cards
NFiD: An NFC based system for Digital Business CardsNFiD: An NFC based system for Digital Business Cards
NFiD: An NFC based system for Digital Business Cards
 
Near field communication (NFC) in android
Near field communication (NFC) in androidNear field communication (NFC) in android
Near field communication (NFC) in android
 
How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks
 
Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes
 
Nfc sfdc mobile_sdk
Nfc sfdc mobile_sdkNfc sfdc mobile_sdk
Nfc sfdc mobile_sdk
 
NFC and the Salesforce Mobile SDK
NFC and the Salesforce Mobile SDKNFC and the Salesforce Mobile SDK
NFC and the Salesforce Mobile SDK
 
How to install and use Kubernetes
How to install and use KubernetesHow to install and use Kubernetes
How to install and use Kubernetes
 

More from Fernando Cejas

Android simple 2d Layout animation
Android simple 2d Layout animationAndroid simple 2d Layout animation
Android simple 2d Layout animation
Fernando Cejas
 

More from Fernando Cejas (15)

The Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on AndroidThe Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on Android
 
It is about philosophy: culture of a good programmer
It is about philosophy: culture of a good programmerIt is about philosophy: culture of a good programmer
It is about philosophy: culture of a good programmer
 
Material Design for Old Schoolers
Material Design for Old SchoolersMaterial Design for Old Schoolers
Material Design for Old Schoolers
 
How to Become the MacGyver of Android Custom Views
How to Become the MacGyver of Android Custom ViewsHow to Become the MacGyver of Android Custom Views
How to Become the MacGyver of Android Custom Views
 
Android UX-UI Design for Fun and Profit
Android UX-UI Design for Fun and ProfitAndroid UX-UI Design for Fun and Profit
Android UX-UI Design for Fun and Profit
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second Edition
 
How ANDROID TESTING changed how we think about Death
How ANDROID TESTING changed how we think about DeathHow ANDROID TESTING changed how we think about Death
How ANDROID TESTING changed how we think about Death
 
Dinosaurs and Androids: The Listview Evolution
Dinosaurs and Androids: The Listview EvolutionDinosaurs and Androids: The Listview Evolution
Dinosaurs and Androids: The Listview Evolution
 
Inside Android Testing
Inside Android TestingInside Android Testing
Inside Android Testing
 
Webview: The fifth element
Webview: The fifth elementWebview: The fifth element
Webview: The fifth element
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device Messaging
 
Android Quick Introduction
Android Quick IntroductionAndroid Quick Introduction
Android Quick Introduction
 
Desarrollo android almacenamiento de datos
Desarrollo android    almacenamiento de datosDesarrollo android    almacenamiento de datos
Desarrollo android almacenamiento de datos
 
Android simple 2d Layout animation
Android simple 2d Layout animationAndroid simple 2d Layout animation
Android simple 2d Layout animation
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Nfc on Android

  • 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 reaction In practice, NFC enables simple and safe two-way interactions among electronic devices 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 emulation Android support: – Read and write (excellent support) – P2P (limited)
  • 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 14 Core 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
  • 16. Android Manifest In 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 scans In 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 Format In 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 app's custom MIME type: String mimeType = "application/root.gast.playground.nfc"; //unique to your app 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 m = new NdefMessage(new NdefRecord[] { record });
  • 19. Activity - Reading NDEF Format In 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 Beam In the .java file for your Activity: //Implement the interface public class BeamActivity extends Activity implements CreateNdefMessageCallback // Register callback mNfcAdapter.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
  • 24. Thanks! When you look at the dark side, careful you must be ... for the dark side looks back. @fernando_cejas www.fernandocejas.com