androidformatnfcmifarendef

Cannot format NdefFormatable NFC tag


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

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)":


Solution

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