NFC stops working after recording in iCODE tags, Android 6.0

I am developing an Android application to read and write various NFC tags. I am facing a problem with a specific tag: iCODE SLI X and iCODE SLI S. After I write the tag information, I cannot do any other action, it looks like NFC stops working correctly because if I restart it, it will actually read the tag. This does not happen if I use a different type of tags, for example, MIFARE Classic 1K. The version for Android is 6.0.

On the other hand, if I try the app on another device with Android 6.1 or 7.0 (exactly the same code), iCODE SLI X and iCODE SLIS work fine, but not MIFARE Classic 1K.

Besides testing different sample codes, I also tried 2 apps on these devices. In "NFC Tools" you can see the same problems as in my application. NXP's "TagWriter" is the only application that works like a charm with all types of tags.

Here is the code I am using to write the tag information:

@Override
protected void onNewIntent(Intent intent) {

    if (mNfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        if (tag != null) {
            try {
                Ndef ndef = Ndef.get(tag);

                NdefRecord text1 = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
                        youstring1.getBytes(Charset.forName("US-ASCII")),
                        null,
                        youstring1.getBytes());

                NdefRecord text2 = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
                        youstring2.getBytes(Charset.forName("US-ASCII")),
                        null,
                        youstring2.getBytes());

                NdefRecord[] records = {text1, text2};

                NdefMessage message = new NdefMessage(records);


                if (ndef != null) {
                    NdefMessage ndefMesg = ndef.getCachedNdefMessage();
                    if (ndefMesg != null) {
                        ndef.connect();
                        ndef.writeNdefMessage(message);
                        ndef.close();
                    }
                } else {
                    NdefFormatable ndefFormatable = NdefFormatable.get(tag);
                    if (ndefFormatable != null) {
                        // initialize tag with new NDEF message
                        try {
                            ndefFormatable.connect();
                            ndefFormatable.format(message);
                            ndefFormatable.close();
                        } finally {
                            try {
                                //ndefFormatable.close();
                            } catch (Exception e) {
                            }
                        }
                    }
                }
            }catch (FormatException |IOException ue){}
        }
    }
}

      

I can't figure out what I might be doing wrong ...

+3


source to share


1 answer


I was able to figure out what was wrong with my application, so I am posting the answer myself. That's what:

When I try to write information about a tag, I first check if the tag is formatted to use the "Ndef" technology on it, unless I use "NdefFormatable" to format the tag.



It is strange that a certain tag in some devices supports "NdefFormatable", and in some it does not. (not sure if this is related to the NFC itself or the OS version). This resulted in NFC feeling bad or not working at all after I tried using "NdefFormatable".

What I am doing now is that I have created this function which gives technologies that I can use in the tag. Depending on this, I use "NdefFormatable" or "NfcV" (for iCODE tags) to read or write to the tag.

+1


source







All Articles