带有APDU命令的Android NFC问题

| 我正在使用IsoDep Tag Tech开发应用程序,以向启用NFC的卡发出APDU命令。 更新:因此,下面看到的问题似乎与我使用的卡的电源要求有关,当我使用电源要求较低的另一卡时,以下症状不会经常出现。 我已经明确地遵循了文档,并成功地实现了该协议。但是,由于取得了不同的成功,我遇到了NFC较低级库的一些问题,这些问题超出了我的代码的控制范围。 我已经实现了以下内容: 待处理的前台调度 意图。 该意图具有技术过滤器 对于IsoDep.class和操作: ACTION_TAG_DISCOVERED 一旦我那么 从Intent Extra中提取标签 发出APDU命令并处理 回应 问题是我注意到了两点: 在Nexus S上,卡的位置取决于成功的通信流程,如果它不在最佳位置,我将收到IOException 如果由于卡已移动​​或不在RF字段中而导致发生太多IOExceptions,我开始看到以下异常(请参阅下文) 我想知道是否还有其他人看到过这些问题?在我的onResume方法中,我没有任何逻辑可以防止多次调用该方法的NFCAdapter实例:enableForegroundDispatch,我应该这样做。 在此先感谢您的帮助。 样本例外1
06-16 12:08:43.351: ERROR/NFC(661): NFC service dead - attempting to recover
06-16 12:08:43.351: ERROR/NFC(661): android.os.DeadObjectException
06-16 12:08:43.351: ERROR/NFC(661):     at android.os.BinderProxy.transact(Native     Method)
06-16 12:08:43.351: ERROR/NFC(661):     at android.nfc.INfcAdapter$Stub$Proxy.enableForegroundDispatch(INfcAdapter.java:528)
06-16 12:08:43.351: ERROR/NFC(661):     at android.nfc.NfcAdapter.enableForegroundDispatch(NfcAdapter.java:494)
06-16 12:08:43.351: ERROR/NFC(661):     at myClass.onResume(MyClass.java:406)
06-16 12:08:43.351: ERROR/NFC(661):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
06-16 12:08:43.351: ERROR/NFC(661):     at android.app.Activity.performResume(Activity.java:3832)
06-16 12:08:43.351: ERROR/NFC(661):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
06-16 12:08:43.351: ERROR/NFC(661):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
06-16 12:08:43.351: ERROR/NFC(661):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
06-16 12:08:43.351: ERROR/NFC(661):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-16 12:08:43.351: ERROR/NFC(661):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-16 12:08:43.351: ERROR/NFC(661):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-16 12:08:43.351: ERROR/NFC(661):     at android.os.Looper.loop(Looper.java:130)
06-16 12:08:43.351: ERROR/NFC(661):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-16 12:08:43.351: ERROR/NFC(661):     at java.lang.reflect.Method.invokeNative(Native Method)
06-16 12:08:43.351: ERROR/NFC(661):     at java.lang.reflect.Method.invoke(Method.java:507)
06-16 12:08:43.351: ERROR/NFC(661):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-16 12:08:43.351: ERROR/NFC(661):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-16 12:08:43.351: ERROR/NFC(661):     at dalvik.system.NativeStart.main(Native Method)
样本异常2
06-16 12:08:18.316: ERROR/MyClass(661): IOException in APDU commands: transceive failed
06-16 12:08:18.316: WARN/System.err(661): java.io.IOException: transceive failed
06-16 12:08:18.324: WARN/System.err(661):     at android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:144)
06-16 12:08:18.324: WARN/System.err(661):     at android.nfc.tech.IsoDep.transceive(IsoDep.java:159)
06-16 12:08:18.328: WARN/System.err(661):     at myClass.handleTagRead(MyClass.java:117)
06-16 12:08:18.328: WARN/System.err(661):     at myClass.onNewIntent(MyClass.java:84)
06-16 12:08:18.332: WARN/System.err(661):     at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1119)
06-16 12:08:18.332: WARN/System.err(661):     at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:1722)
06-16 12:08:18.335: WARN/System.err(661):     at android.app.ActivityThread.performNewIntents(ActivityThread.java:1734)
06-16 12:08:18.335: WARN/System.err(661):     at android.app.ActivityThread.handleNewIntent(ActivityThread.java:1742)
06-16 12:08:18.339: WARN/System.err(661):     at android.app.ActivityThread.access$2300(ActivityThread.java:117)
06-16 12:08:18.343: WARN/System.err(661):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:978)
06-16 12:08:18.343: WARN/System.err(661):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-16 12:08:18.347: WARN/System.err(661):     at android.os.Looper.loop(Looper.java:130)
06-16 12:08:18.347: WARN/System.err(661):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-16 12:08:18.351: WARN/System.err(661):     at java.lang.reflect.Method.invokeNative(Native Method)
06-16 12:08:18.351: WARN/System.err(661):     at java.lang.reflect.Method.invoke(Method.java:507)
06-16 12:08:18.355: WARN/System.err(661):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-16 12:08:18.355: WARN/System.err(661):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-16 12:08:18.359: WARN/System.err(661):     at dalvik.system.NativeStart.main(Native Method)
06-16 12:08:18.359: DEBUG/MyClass(661): Setting up for ForegroundDispatch for NFC ISO DEP
06-16 12:08:18.492: DEBUG/NativeNfcTag(871): Tag lost, restarting polling loop
06-16 12:08:19.269: WARN/NfcService(871): Failed to connect to tag
06-16 12:08:23.980: ERROR/NFC JNI(871): phLibNfc_RemoteDev_Connect(RW) returned 0x00ff[NFCSTATUS_FAILED]
06-16 12:08:23.980: WARN/NfcService(871): Failed to connect to tag
06-16 12:08:23.980: ERROR/NFC JNI(871): doDisconnect() - Target already disconnected
样本例外3
06-16 12:08:15.468: DEBUG/MyClass(661): Recieved a TAG
06-16 12:08:15.468: DEBUG/MyClass(661): Supported Technology of for recieve    d tag: android.nfc.tech.IsoDep
06-16 12:08:15.468: DEBUG/MyClass(661): Supported Technology of for recieved tag: android.nfc.tech.NfcA
06-16 12:08:15.468: DEBUG/MyClass(661): Supported Technology of for recieved tag: android.nfc.tech.MifareClassic
06-16 12:08:15.484: ERROR/MyClass(661): Failed to connect to aTag Reason: null
06-16 12:08:15.484: WARN/System.err(661): java.io.IOException
06-16 12:08:15.484: WARN/System.err(661):     at android.nfc.tech.BasicTagTechnology.connect(BasicTagTechnology.java:81)
06-16 12:08:15.484: WARN/System.err(661):     at android.nfc.tech.IsoDep.connect(IsoDep.java:39)
06-16 12:08:15.484: WARN/System.err(661):     at myClass.handleTagRead(ConfirmPaymentScreen.java:107)
06-16 12:08:15.484: WARN/System.err(661):     at myClass.onNewIntent(ConfirmPaymentScreen.java:84)
06-16 12:08:15.484: WARN/System.err(661):     at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1119)
06-16 12:08:15.484: WARN/System.err(661):     at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:1722)
06-16 12:08:15.484: WARN/System.err(661):     at android.app.ActivityThread.performNewIntents(ActivityThread.java:1734)
06-16 12:08:15.484: WARN/System.err(661):     at android.app.ActivityThread.handleNewIntent(ActivityThread.java:1742)
06-16 12:08:15.484: WARN/System.err(661):     at android.app.ActivityThread.access$2300(ActivityThread.java:117)
06-16 12:08:15.484: WARN/System.err(661):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:978)
06-16 12:08:15.484: WARN/System.err(661):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-16 12:08:15.484: WARN/System.err(661):     at android.os.Looper.loop(Looper.java:130)
06-16 12:08:15.484: WARN/System.err(661):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-16 12:08:15.484: WARN/System.err(661):     at java.lang.reflect.Method.invokeNative(Native Method)
06-16 12:08:15.484: WARN/System.err(661):     at java.lang.reflect.Method.invoke(Method.java:507)
06-16 12:08:15.484: WARN/System.err(661):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-16 12:08:15.484: WARN/System.err(661):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-16 12:08:15.484: WARN/System.err(661):     at dalvik.system.NativeStart.main(Native Method)
06-16 12:08:15.484: DEBUG/MyClass(661): Failed to connect to tag
06-16 12:08:15.484: DEBUG/MyClass(661): Setting up for ForegroundDispatch for NFC ISO DEP
06-16 12:08:15.609: ERROR/NFC JNI(871): phLibNfc_RemoteDev_CheckPresence() returned 0x0095[NFCSTATUS_INVALID_HANDLE]
06-16 12:08:15.609: DEBUG/NativeNfcTag(871): Tag lost, restarting polling loop
06-16 12:08:15.609: ERROR/NFC JNI(871): phLibNfc_RemoteDev_Disconnect(294f58) returned 0x0095[NFCSTATUS_INVALID_HANDLE]
    
已邀请:
        因此,我知道是什么原因造成的,我尝试读取的某些RFID标签的功耗要求比手机要高。令人不安的是/如果它在坏地方放置的时间过长,电话就会掉下来...     
        标签的射频功能不足仍然是这里的答案吗? 我有自供电的nt3h2xxx系列标签,它们在最近的手机(诺基亚3)上表现出相同的行为:nfca.tranceive(0xA2 / 0xA6 ...)将数据成功写入标签(在稍后检查之后),但抛出\“ Transceive failed \ ”。虽然nfca.tranceive(读取命令)工作正常。 W / System.err:java.io.IOException:收发失败 W / System.err:位于android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:52) W / System.err:位于android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:151) W / System.err:位于android.nfc.tech.NfcA.transceive(NfcA.java:120) 也许我的标签线圈没有足够大,无法将4位ACK响应下拉至成功的标签快速写入。虽然标签读取可以,因为标签响应具有更多位(仅在此处猜测)。 解决方法是捕获收发的IOexception并忽略它。然后,完成所有操作后,从标记中快速读取以查看快速写入是否有效。     

要回复问题请先登录注册