• Cart$0.00
  • Register
  • Log In
  • Cart
  • Checkout

Flomio

  • Concepts
  • Products
  • Docs
  • Forums

Blog

  • Follow us on Twitter
  • Join our Facebook Group
  • RSS

Blog

Android NFC Tutorial – Part 1

this entry has 0 Comments/ in Posts / by John
May 18, 2012

This post assumes basic familiarity with Java and the Android SDK.  It gives you a brief intro on how to talk to the NFC API to read a tag and subscribe to an event that detects it.  

Setting up the Activity

[java]
public class Main extends Activity
{
  @Override
  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.read_tag);
  }

  @Override
  protected void onResume() {
     //Process the intent that started this activity. It should be a Tag Discovery related intent
     this.parseIntent(this.getIntent());
   }
[/java]

Processing the NFC Tag event

[java]
boolean parseIntent(Intent intent) {
 String action = intent.getAction();

 if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
    Tag tag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    boolean success = FlomioNdefHelper.writeUrlToTag(url, tag);
 } else {
    return false;
 }
}
[/java]

AndroidManifest.xml

[xml]
 <uses-permission android:name="android.permission.NFC" />
[/xml]

[xml]
<activity android:name=".ReadNfcTag" >
 <intent-filter>
  <action android:name="android.nfc.action.NDEF_DISCOVERED" />
  <category android:name="android.intent.category.DEFAULT" />
  <data
   android:host="flomio.com"
   android:scheme="http" /></pre>
 </intent-filter>
</activity>
[/xml]
Tags: Android, NFC, Tutorials
← Understanding NDEF Messages (previous entry)
(next entry) NFC Still Has Legs: Flomio Closes On Half A Million In Seed Funding For NFC-Based Products & Services →
Related Posts
The Basics of NDEF
MIT pimps RFID sweetness
Understanding NDEF Messages
NFC for Anyone
Comments

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Best UX: Provisioning Headless IoT Devices
  • SmartCart @ AWS re:Invent
  • BagBot: Money2020 hackaton winner!
  • iPhone7 NFC Reader Performance Tests
  • Apple opens NFC to Developers with iOS11

Recent Topics

  • ACM1252U-Z2 NFC tap via Android/IOS
  • getfastpass
  • NFC Chip reader hardware
  • Order 106232
  • NFC testing solution
  • Forums
  • Blog
  • Shop
  • About

140 CHAR WISDOM!

Flomio
  • We built this for the #redis hackathon... vote for our project here: https://t.co/gsaYjYfAa9 https://t.co/Za0hTJvzww 11:00:04 AM June 03, 2020 from Twitter for iPhone
  • Miami’s startup ecosystem continues to grow ... welcome @convertflow ! https://t.co/wYwUiGWhCz 08:43:48 AM April 09, 2020 from Twitter for iPhone
© Copyright - Flomio, Inc.
View FLOMIO INC profile on Ariba Discovery
  • Send us Mail
  • Follow us on Twitter
  • Join our Facebook Group
  • Subscribe to our RSS Feed