【发布时间】:2015-04-20 10:16:06
【问题描述】:
我想格式化 Mifare Ultralight C 来处理 NDEF 消息。我已经编写了下面的代码,它在 Mifare Classic 1K 芯片上工作得很好,但是当我尝试连接到 Ultralight C 芯片时它得到一个 IOExeption。
NdefFormatable format = NdefFormatable.get(tag)
if(format != null){
try {
format.connect();
format.format(new NdefMessage(new NdefRecord(NdefRecord.TNF_EMPTY, null, null, null)));
format.close();
Toast.makeText(getApplicationContext(), "Tag formated.", Toast.LENGTH_LONG).show();
}catch (IOException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "Failed to connect", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (FormatException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "Failed Format", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
else
Toast.makeText(getApplicationContext(), "Tag unformatable or already formatted to Ndef.", Toast.LENGTH_LONG).show();
}
有谁知道错误可能是什么以及为什么代码适用于 1k 芯片而不适用于 Ultralight C?标签是全新的,完全空白。
这是 logcat 中的输出:
04-21 08:49:27.300: W/System.err(9351): java.io.IOException
04-21 08:49:27.300: W/System.err(9351): at android.nfc.tech.NdefFormatable.format(NdefFormatable.java:132)
04-21 08:49:27.300: W/System.err(9351): at android.nfc.tech.NdefFormatable.format(NdefFormatable.java:95)
04-21 08:49:27.300: W/System.err(9351): at com.example.exjobb.nfc.FormatTag.formatTag(FormatTag.java:69)
04-21 08:49:27.300: W/System.err(9351): at com.example.exjobb.nfc.FormatTag.onNewIntent(FormatTag.java:58
04-21 08:49:27.300: W/System.err(9351): at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1178)
04-21 08:49:27.300: W/System.err(9351): at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2418)
04-21 08:49:27.300: W/System.err(9351): at android.app.ActivityThread.performNewIntents(ActivityThread.java:2431)
04-21 08:49:27.300: W/System.err(9351): at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2440)
04-21 08:49:27.300: W/System.err(9351): at android.app.ActivityThread.access$1500(ActivityThread.java:159)
04-21 08:49:27.300: W/System.err(9351): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1387)
04-21 08:49:27.300: W/System.err(9351): at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 08:49:27.300: W/System.err(9351): at android.os.Looper.loop(Looper.java:176)
04-21 08:49:27.300: W/System.err(9351): at android.app.ActivityThread.main(ActivityThread.java:5419)
04-21 08:49:27.300: W/System.err(9351): at java.lang.reflect.Method.invokeNative(Native Method)
04-21 08:49:27.300: W/System.err(9351): at java.lang.reflect.Method.invoke(Method.java:525)
04-21 08:49:27.305: W/System.err(9351): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
04-21 08:49:27.305: W/System.err(9351): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
04-21 08:49:27.305: W/System.err(9351): at dalvik.system.NativeStart.main(Native Method)
【问题讨论】:
-
请在 logcat 中分享 stacktrace
-
这是一个空白(即以前没有使用过)Ultralight C 标签吗?
-
@LaurentY logcat中的stacktrace已添加。
-
@MichaelRoland 标签是全新的,完全空白。
-
logcat 中是否还有其他内容可以指示格式化失败的原因?您是否还使用某些 NFC 阅读器应用程序检查 CC 块(块 3)为空且未设置锁定位?