在使用 Ndef.writeNdefMessage 写入 NFC 标签时,我在 catch 块中收到 IOException 错误。检查 Logcat 显示 PhLibNfc_Ndef_Write 函数触发了 NFCSTATUS_INSUFFICIENT_STORAGE 错误,这有效地触发了 IOException。有没有办法在应用层捕获这个 NFCSTATUS_INSUFFICIENT_STORAGE 错误。我搜索了很多,但总是以 PhLibNfc_Ndef_Write 函数的源代码结束。
我用来写标签的代码
final NdefMessage message = new NdefMessage(bytearray);
final NdefFormatable ndefFormatable = NdefFormatable.get(tag);
if(ndefFormatable == null){
final Ndef ndef = Ndef.get(tag);
ndef.connect();
if(ndef.isConnected() && ndef.isWritable()){
new Thread(new Runnable() {
public void run() {
try {
// this logic is not working. Status quo remains
int actlen = ndef.getMaxSize();
if (actlen < arrayLen) {
Toast.makeText(tagHandler.this, "Space not available", 20).show();
}
ndef.writeNdefMessage(message); <-- error is triggered here
} catch (IOException e) {
e.printStackTrace();
}
}
}).start(); //runnable
ndef.close();
return true;
}
我遇到的 logcat 错误
E/NFC JNI(705): phLibNfc_Ndef_Write() returned 0x001f[NFCSTATUS_INSUFFICIENT_STORAGE]
W/System.err(547): java.io.IOException
W/System.err(547): at android.nfc.tech.Ndef.writeNdefMessage(Ndef.java:313)
W/System.err(547): at com.example.tagreader.tagHandler$2.run(tagHandler.java:270)
W/System.err(547): at java.lang.Thread.run(Thread.java:856)
对捕获 NFCSTATUS_INSUFFICIENT_STORAGE 错误有任何帮助吗?