Writing NDEF Messages
21
void writeUrlToTag(Intent intent, String url)
throws IOException, FormatException {
String action = intent.getAction();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Ndef ndefTag = Ndef.get(tag);
NdefRecord rec = NdefRecordRtdUri.createRtdUriRecord(url);
NdefMessage msg = new NdefMessage(new NdefRecord[] { rec });
ndefTag.connect();
ndefTag.writeNdefMessage(msg);
ndefTag.close();
}
}
Comments to this Manuals