Created
February 2, 2013 15:40
-
-
Save NetworksAreMadeOfString/4697892 to your computer and use it in GitHub Desktop.
A very basic (no real error handling / tag formatting etc) example of writing Android Application Records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onNewIntent(Intent intent) | |
{ | |
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); | |
WriteTag(tagFromIntent); | |
} | |
public void WriteTag(final Tag receivedTag) | |
{ | |
((Thread) new Thread() | |
{ | |
public void run() | |
{ | |
NdefRecord aaRecord = NdefRecord.createApplicationRecord("io.d0"); | |
NdefRecord idRecord = NdefRecord.createExternal("io.d0:tag", Integer.toString(tagType), tagMetaData.toString().getBytes(Charset.forName("US-ASCII"))); | |
try | |
{ | |
thisNdef = Ndef.get(receivedTag); | |
} | |
catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
if(thisNdef.isWritable()) | |
{ | |
NdefMessage tagMsg = new NdefMessage(new NdefRecord[]{idRecord,aaRecord}); | |
thisNdef.writeNdefMessage(tagMsg); | |
thisNdef.makeReadOnly(); | |
thisNdef.close(); | |
} | |
} | |
}).start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment