1
votes

I'm developing an Android application that's using NFC. I have some NFC card with the following tech-list:

  • android.nfc.tech.NfcA
  • android.nfc.tech.MifareClassic
  • android.nfc.tech.NdefFormatable

But I cannot format those tags using NdefFormatable.format(message). Instead, I get an IOException.

The code:

try {
    NdefRecord[] records1 = { createRecord("000000") };
    NdefMessage message1 = new NdefMessage(records1);
    formatable.format(message1);
    res = 1;
}

The stacktrace gave these logs:

W/System.err: java.io.IOException
W/System.err:     at android.nfc.tech.NdefFormatable.format(NdefFormatable.java:131)
W/System.err:     at android.nfc.tech.NdefFormatable.format(NdefFormatable.java:94)
                  at com.example.peng.nfcreadwrite.MainActivity.write(MainActivity.java:170)
W/System.err:     at com.example.peng.nfcreadwrite.MainActivity.access$000(MainActivity.java:27)
                  at com.example.peng.nfcreadwrite.MainActivity$1.onClick(MainActivity.java:60)
                  at android.view.View.performClick(View.java:6877)
W/System.err:     at android.widget.TextView.performClick(TextView.java:12651)
                  at android.view.View$PerformClick.run(View.java:26069)
                  at android.os.Handler.handleCallback(Handler.java:789)
                  at android.os.Handler.dispatchMessage(Handler.java:98)
W/System.err:     at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6938)
                  at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Maybe someone can give me something to look into, cause I'm fairly new into NFC on Android.

Edit

This is the screenshot I took using Mifare Classic Tool. It shows for sectors 4 to 8 that "no keys found(or dead sector)":

1
Was the tag used for something else before? Could it be that some of the sectors of the MIFARE Classic card are locked with some key other than the transport key? You might want to try to read the tag with some generic tag reader app (such as my NFC TagInfo or NXP TagInfo) to verify that all sectors are writable with transport keys.Michael Roland
I'm sorry for the late reply, These cards were provided by some third party vendor my workplace used, they said it's a blank card. I have checked using the Mifare Classic Tool, and found out that all of the cards had sector 4 to 8 shown message No keys found(or dead sector). (please see my updated question for screenshot of the card I checked)caesario pradana
Hi, I'm facing the same problem and posted a question here stackoverflow.com/questions/61784673/… Can you share a full solution please?Sam Reyes

1 Answers

1
votes

The NDEF formatting procedure for MIFARE Classic tags on Android expects the tags to be empty and accessible (read & write) with the default transport key (FFFFFFFFFFFF) or certain standard keys (MAD key for sector 0, NDEF key for other sectors). If some sectors of the tag are inaccessible, Android won't be able to format the tag for use with NDEF.

Consequently, your tags are unusable for your purpose. Though you might be able to manually format the tag to skip those locked sectors. I'm not quite sure if Android is capable of using these tags then.