Skip to content

Instantly share code, notes, and snippets.

@NetworksAreMadeOfString
Created February 2, 2013 15:40
Show Gist options
  • Save NetworksAreMadeOfString/4697892 to your computer and use it in GitHub Desktop.
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
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