Reputation:
I've a problem when I try to write a NFC A tag on Android 2.3.6 (nexus S). I use the code from this example: http://www.jessechen.net/blog/how-to-nfc-on-the-android-platform/
More precisely, when I do the Ndef.get(mytag) I get null so I cannot write my tag.
Here is the code from which I get a null references (the 'tag' value is not null), only the ndef.
Ndef ndef = Ndef.get(tag);
if (ndef != null) {
ndef.connect();
if (!ndef.isWritable()) {
return false;
}
if (ndef.getMaxSize() < size) {
return false;
}
ndef.writeNdefMessage(message);
return true;
}
Thank you for you help !!!
Upvotes: 0
Views: 5208
Reputation: 10228
Your tag may not yet be formatted for NDEF message storage or may not be able to store NDEF messages at all.
Check whether NdefFormatable.get(tag)
returns something unequal to null
.
Then use NdefFormatable.format(message)
to try to write your message.
If NdefFormatable.get(tag)
returns null
, then either Android has no means to format the tag or the tag is incompatible to NDEF storage.
(Alternatively, you may want to use TagWriter, https://market.android.com/details?id=com.nxp.nfc.tagwriter to format and write your tag.)
Upvotes: 2
Reputation: 2132
Try NfcA.get(tag) instead. Not sure why you are getting the error though, but trying the other class might work.
Upvotes: 0