首页 > 解决方案 > NFC interaction between Android devices triggers Android Beam instead of HCE

问题描述

I'm developing payment terminal simulator that acts as a standalone POS terminal. It works ok with chip contactless cards (it can communicate with them on proper protocol), initiate transaction, read data from them etc.

I also wanted to handle transactions done by Google Pay (POS terminals recognize Google Pay as normal contactless card - same protocol). But when I have one Android device with my POS terminal app running, and another Android device with Google Pay, when I touch both devices together, my POS app is minimized and "Touch to send beam" is shown. I would have expected that instead the onNewIntent method is called in the POS terminal app.

How to handle this? The expected behaviour is that my app (POS terminal) is not minimized, and on the other phone the Google Pay app is triggered.

Should I send something at the begginng, so that Android with Google Pay can recognize that this is a payment transaction? Or maybe some specific intent-filter to handle this on the POS terminal Android device?

I also observed that in one of three to four tries, I seem to get the expected behaviour - onNewIntent is called in my app. This looks like some race condition beetween my app and the default Android Beam behaviour.

标签: androidnfchcenfc-p2pandroid-beam

解决方案


您不能使用常规标签调度机制(意图过滤器或前台调度系统)与另一个在卡模拟 (HCE) 模式下运行的 Android 设备进行交互。问题是这两个 Android 设备通常会自动发现它们的点对点模式功能。因此,它们以 P2P 模式连接并触发 Android Beam(在 P2P 之上的 LLCP 之上的 SNEP)。请注意,即使您在两台设备上都禁用了 Android Beam,它们仍然会选择 P2P 模式。

为了克服这个问题,您需要使用阅读器模式 API。这允许您在活动处于前台时禁用 P2P 模式并选择性地启用读取器/写入器模式功能(例如不同的技术)。


推荐阅读