mifare nfc android,使用Android NFC写入Mifare标签?

开发者在尝试在全新Mifare1K标签上写入'HelloWorld'时遇到问题,代码执行时出现收发失败异常。本文将深入解析错误原因及解决方案,涉及NFC技术和Mifare Classic API的使用。
摘要由CSDN通过智能技术生成

我正在尝试在Mifare 1K标签上的第0扇区的第一个块写一个简单的“Hello World”字符串.标签是全新的,具有默认配置.扇区尾部(块3)在读取时为:00 00 00 00 00 00 00 00 ff 07 80 69 ff ff ff ff ff ff ff ff.因此,访问条件是ff 07 80 69,这意味着我可以使用密钥A在每个块上进行读写.

不过,我无法在标签上写任何东西.这是我的代码:

try {

mfc.connect();

boolean auth = false;

auth = mfc.authenticateSectorWithKeyA(0,MifareClassic.KEY_DEFAULT);

if (auth) {

String text = "Hello, World!";

byte[] value = text.getBytes();

byte[] toWrite = new byte[MifareClassic.BLOCK_SIZE];

for (int i=0; i

if (i < value.length) toWrite[i] = value[i];

else toWrite[i] = 0;

}

mfc.writeBlock(0, toWrite);

}

我收到以下异常:收发失败.

我究竟做错了什么?

这是堆栈跟踪:

07-09 00:19:44.836: W/System.err(13167): at android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:52)

07-09 00:19:44.843: W/System.err(13167): at android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:151)

07-09 00:19:44.843: W/System.err(13167): at android.nfc.tech.MifareClassic.writeBlock(MifareClassic.java:453)

07-09 00:19:44.843: W/System.err(13167): at com.example.andorid.apis.mifare.MainActivity.resolveIntent(MainActivity.java:128)

07-09 00:19:44.843: W/System.err(13167): at com.example.andorid.apis.mifare.MainActivity.onNewIntent(MainActivity.java:275)

07-09 00:19:44.843: W/System.err(13167): at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1123)

07-09 00:19:44.843: W/System.err(13167): at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2041)

07-09 00:19:44.843: W/System.err(13167): at android.app.ActivityThread.performNewIntents(ActivityThread.java:2054)

07-09 00:19:44.843: W/System.err(13167): at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2063)

07-09 00:19:44.843: W/System.err(13167): at android.app.ActivityThread.access$1400(ActivityThread.java:122)

07-09 00:19:44.843: W/System.err(13167): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1193)

07-09 00:19:44.851: W/System.err(13167): at android.os.Handler.dispatchMessage(Handler.java:99)

07-09 00:19:44.851: W/System.err(13167): at android.os.Looper.loop(Looper.java:137)

07-09 00:19:44.851: W/System.err(13167): at android.app.ActivityThread.main(ActivityThread.java:4340)

07-09 00:19:44.851: W/System.err(13167): at java.lang.reflect.Method.invokeNative(Native Method)

07-09 00:19:44.851: W/System.err(13167): at java.lang.reflect.Method.invoke(Method.java:511)

07-09 00:19:44.851: W/System.err(13167): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

07-09 00:19:44.851: W/System.err(13167): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

07-09 00:19:44.851: W/System.err(13167): at dalvik.system.NativeStart.main(Native Method)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值