Android的NFC问题APDU命令 [英] Android NFC Issue with APDU Commands

查看:550
本文介绍了Android的NFC问题APDU命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IsoDep标签技术发出APDU命令启用NFC卡的应用程序。

更新:所以看到下面似乎与卡片我使用的,当我使用不同的卡,更低的功率要求以下症状不会出现频繁的电力需求问题。

我已经明确地跟着文档,并有成功的管理来实现的协议。然而成败参半,我遇到了一些问题,超出了我的code中的控制NFC较低水平库。

我已经实现了以下内容:

  • 在一个待定的前景调度 意图。
  • 在这样做的目的有一个高科技过滤器 为IsoDep.class和行动:
    • ACTION_TAG_DISCOVERED
  • 当我再 从意向额外提取标签 问题APDU命令和处理 响应

问题是,我注意到两件事情:

在Nexus S的卡的位置是依赖于成功的通信流量,如果不是在甜蜜点,我会得到一个IOException 如果我得到太多的IOExceptions因为卡移动或不留在RF场我开始看到以下excpetions(见下文) 我想知道是否有人看到了这些问题?在我的onResume方法,我没有任何逻辑prevent多次调用该方法的NFCAdapter实例:enableForegroundDispatch,我应该这样做。

在此先感谢您的帮助。

样品异常1

  12月6号至16日:08:43.351:ERROR / NFC(661):NFC服务死了 - 试图恢复
一十二月6日至16日:08:43.351:ERROR / NFC(661):android.os.DeadObjectException
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.os.BinderProxy.transact(本机方法)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.nfc.INfcAdapter $存根$ Proxy.enableForegroundDispatch(INfcAdapter.java:528)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.nfc.NfcAdapter.enableForegroundDispatch(NfcAdapter.java:494)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在myClass.onResume(MyClass.java:406)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.app.Activity.performResume(Activity.java:3832)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.os.Handler.dispatchMessage(Handler.java:99)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.os.Looper.loop(Looper.java:130)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在android.app.ActivityThread.main(ActivityThread.java:3683)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在java.lang.reflect.Method.invokeNative(本机方法)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在java.lang.reflect.Method.invoke(Method.java:507)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
一十二月6日至16日:08:43.351:ERROR / NFC(661):在dalvik.system.NativeStart.main(本机方法)
 

样品异常2

  12月6号至16日:08:18.316:ERROR / MyClass的(661):IOException的APDU命令:收发失败
一十二月6日至16日:08:18.316:WARN / System.err的(661):java.io.IOException异常:收发失败
一十二月6日至16日:08:18.324:WARN / System.err的(661):在android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:144)
一十二月6日至16日:08:18.324:WARN / System.err的(661):在android.nfc.tech.IsoDep.transceive(IsoDep.java:159)
一十二月6日至16日:08:18.328:WARN / System.err的(661):在myClass.handleTagRead(MyClass.java:117)
一十二月6日至16日:08:18.328:WARN / System.err的(661):在myClass.onNewIntent(MyClass.java:84)
一十二月6日至16日:08:18.332:WARN / System.err的(661):在android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1119)
一十二月6日至16日:08:18.332:WARN / System.err的(661):在android.app.ActivityThread.deliverNewIntents(ActivityThread.java:1722)
一十二月6日至16日:08:18.335:WARN / System.err的(661):在android.app.ActivityThread.performNewIntents(ActivityThread.java:1734)
一十二月6日至16日:08:18.335:WARN / System.err的(661):在android.app.ActivityThread.handleNewIntent(ActivityThread.java:1742)
一十二月6日至16日:08:18.339:WARN / System.err的(661):在android.app.ActivityThread.access $ 2300(ActivityThread.java:117)
一十二月6日至16日:08:18.343:WARN / System.err的(661):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:978)
一十二月6日至16日:08:18.343:WARN / System.err的(661):在android.os.Handler.dispatchMessage(Handler.java:99)
一十二月6日至16日:08:18.347:WARN / System.err的(661):在android.os.Looper.loop(Looper.java:130)
一十二月6日至16日:08:18.347:WARN / System.err的(661):在android.app.ActivityThread.main(ActivityThread.java:3683)
一十二月6日至16日:08:18.351:WARN / System.err的(661):在java.lang.reflect.Method.invokeNative(本机方法)
一十二月6日至16日:08:18.351:WARN / System.err的(661):在java.lang.reflect.Method.invoke(Method.java:507)
一十二月6日至16日:08:18.355:WARN / System.err的(661):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
一十二月6日至16日:08:18.355:WARN / System.err的(661):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
一十二月6日至16日:08:18.359:WARN / System.err的(661):在dalvik.system.NativeStart.main(本机方法)
一十二月6日至16日:08:18.359:DEBUG / MyClass的(661):设置为ForegroundDispatch的NFC ISO DEP
一十二月6日至16日:08:18.492:DEBUG / NativeNfcTag(871):标签丢失,重新启动轮询循环
一十二月6日至16日:08:19.269:WARN / NfcService(871):未能连接到标签
一十二月6日至16日:08:23.980:ERROR / NFC JNI(871):phLibNfc_RemoteDev_Connect(RW)返回放在0x00FF [NFCSTATUS_FAILED]
一十二月6日至16日:08:23.980:WARN / NfcService(871):未能连接到标签
一十二月6日至16日:08:23.980:ERROR / NFC JNI(871):doDisconnect() - 目标已断开连接
 

Sameple例外3

  12月6号至16日:08:15.468:DEBUG / MyClass的(661):收到了一条TAG
一十二月6日至16日:08:15.468:DEBUG / MyClass的(661):支持对免费获赠ð标签技术:android.nfc.tech.IsoDep
一十二月6日至16日:08:15.468:DEBUG / MyClass的(661):支持为:收到标签技术:android.nfc.tech.NfcA
一十二月6日至16日:08:15.468:DEBUG / MyClass的(661):支持为:收到标签技术:android.nfc.tech.MifareClassic
一十二月6日至16日:08:15.484:ERROR / MyClass的(661):无法连接到ATAG原因:空
一十二月6日至16日:08:15.484:WARN / System.err的(661):产生java.io.IOException
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.nfc.tech.BasicTagTechnology.connect(BasicTagTechnology.java:81)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.nfc.tech.IsoDep.connect(IsoDep.java:39)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在myClass.handleTagRead(ConfirmPaymentScreen.java:107)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在myClass.onNewIntent(ConfirmPaymentScreen.java:84)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1119)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.app.ActivityThread.deliverNewIntents(ActivityThread.java:1722)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.app.ActivityThread.performNewIntents(ActivityThread.java:1734)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.app.ActivityThread.handleNewIntent(ActivityThread.java:1742)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.app.ActivityThread.access $ 2300(ActivityThread.java:117)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:978)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.os.Handler.dispatchMessage(Handler.java:99)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.os.Looper.loop(Looper.java:130)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在android.app.ActivityThread.main(ActivityThread.java:3683)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在java.lang.reflect.Method.invokeNative(本机方法)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在java.lang.reflect.Method.invoke(Method.java:507)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
一十二月6日至16日:08:15.484:WARN / System.err的(661):在dalvik.system.NativeStart.main(本机方法)
一十二月6日至16日:08:15.484:DEBUG / MyClass的(661):未能连接到标签
一十二月6日至16日:08:15.484:DEBUG / MyClass的(661):设置为ForegroundDispatch的NFC ISO DEP
一十二月6日至16日:08:15.609:ERROR / NFC JNI(871):phLibNfc_RemoteDev_Check presence()返回0x0095 [NFCSTATUS_INVALID_HANDLE]
一十二月6日至16日:08:15.609:DEBUG / NativeNfcTag(871):标签丢失,重新启动轮询循环
一十二月6日至16日:08:15.609:ERROR / NFC JNI(871):phLibNfc_RemoteDev_Disconnect(294f58)返回0x0095 [NFCSTATUS_INVALID_HANDLE]
 

解决方案

所以我知道是什么原因造成这种情况,一些RFID标签,我想读了更高的功耗要求比手机是有能力的。镦粗的事情是/是手机翻倒,如果它得到一个不好的地方太久...

I am working on an Application using the IsoDep Tag Tech to issue APDU commands to an NFC enabled card.

UPDATE: So the issues seen below seem related to the power requirements of the cards I am using, when I use a different card with lower power requirements the below symptoms don't occur as frequently.

I have followed the documentation explicitly and have a successful managed to implement the protocol. However with mixed success I am experiencing some issues with the NFC lower level libraries beyond the control of my code.

I have implemented the following:

  • Foreground dispatching of a Pending Intent.
  • The intent has a tech filter for IsoDep.class and action:
    • ACTION_TAG_DISCOVERED
  • Once the I then extract the Tag from the Intent Extra Issue APDU commands and process the responses

The issue is that I have noticed a couple of things:

On the Nexus S the position of the card is dependent on a successful communication flow, if it is not in the sweet spot I will receive an IOException If I get too many IOExceptions because the card has moved or not remained in the RF field I start to see the following excpetions (see below) I was wondering if anyone else had seen these issues? In my onResume method I don't have any logic to prevent multiple calls to the NFCAdapter instance of the method: enableForegroundDispatch, should I be doing this.

Thanks in advance for any help.

Sample Exception 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)

Sample Exception 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

Sameple Exception 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]

解决方案

So I know what is causing this, some of the RFID tags I was trying to read had a higher power consumption requirement than the phone was capable of. The upsetting thing was/is the phone falls over if it gets in a bad place for too long...

这篇关于Android的NFC问题APDU命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆