简体   繁体   中英

Android NFC Write NFCA tag

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 !!!

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.)

Try NfcA.get(tag) instead. Not sure why you are getting the error though, but trying the other class might work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM