【发布时间】:2016-03-14 10:40:20
【问题描述】:
我想使用以下代码格式化一张从未使用过的 MIFARE Ultralight 卡:
NdefFormatable formatable = NdefFormatable.get(tag);
if (formatable != null) {
String result = "Afifly";
try {
formatable.connect();
try {
formatable.format(new NdefMessage(new NdefRecord(NdefRecord.TNF_EMPTY, null, null, null)));
} catch (Exception e) {
// let the user know the tag refused to format
System.out.println("error ");//+getStackTrace(e));
result = "Fail 1";
}
} catch (Exception e) {
// let the user know the tag refused to connect
System.out.println("eeeerrror 2"+e);
result = "Fail 2";
} finally {
try {
formatable.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return;
}
但是在调用formatable.format(...)方法时总是抛出一个IOException(没有任何有意义的消息)。
我尝试了其他几张卡片,结果都一样。但是,这些卡可以使用 NXP TagWriter 进行格式化。
我已找到问题/答案“Formatting a Mifare Ultralight C to NDEF”,但此解决方案不适用于我。我仍然得到相同的 IOException。
标签的前四页(0-3页)包含以下字节:
04 F1 E9 94 42 AB 4A 80 23 48 00 00(清除所有锁定位) 00 00 00 00(无能力容器)因此,标签为空且未锁定。
【问题讨论】:
-
tag.getTechList()列举了哪些技术? IOException 是否包含任何消息 (e.getMessage())?在尝试使用format(...)之前,标签第3-5页的内容是什么? -
列举了3个技术人员:
android.nfc.tech.NfcAandroid.nfc.tech.MifareUltraLightandroid.nfc.tech.NdefFormatable和e.getMessage()打印出null -
当我阅读它时,它给了我一个包含值
4 -15 -23 -108 66 -85 74 -128 35 72 and 6 zero的字节数组,所以如果它是 4 字节页面,它在第 3 页上给了我35 72 0 0并且在 4 和 5 上只有 0 。 .. 当我致电MifareUltralight.get(tag).readPages(0)时,每张未格式化的卡上都有不同的文字 -
标签确实是空的并且没有被锁定,所以如果您的 Android 设备支持该标签类型的格式,格式应该正常工作。您可以尝试的另一件事是使用不同的 NDEF 消息(例如,一些包含非空记录的消息)。如果这不起作用,您的设备平台可能不支持使用
NdefFormatable格式化该标签类型,即使它错误地提供了NdefFormatable标签技术。不幸的是,确实存在这样的设备。如果是这种情况,我建议您手动执行格式化程序。 -
感谢您的回答。我尝试使用非空记录但没有成功......如果我的设备平台不支持格式化,为什么格式化在与 tagwriter 的应用程序相同的设备上工作?他们正在使用 NdefFormatable 的其他东西?那是什么?
标签: android format nfc mifare ndef