android - 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.
解决方案
您不能使用常规标签调度机制(意图过滤器或前台调度系统)与另一个在卡模拟 (HCE) 模式下运行的 Android 设备进行交互。问题是这两个 Android 设备通常会自动发现它们的点对点模式功能。因此,它们以 P2P 模式连接并触发 Android Beam(在 P2P 之上的 LLCP 之上的 SNEP)。请注意,即使您在两台设备上都禁用了 Android Beam,它们仍然会选择 P2P 模式。
为了克服这个问题,您需要使用阅读器模式 API。这允许您在活动处于前台时禁用 P2P 模式并选择性地启用读取器/写入器模式功能(例如不同的技术)。
推荐阅读
- reactjs - 最大选择长度在反应选择中不可用
- json - Swift:如何使用 JSON 数据动态配置具有多个部分的 tableview
- datastax - 如何在 DevCenter 的 cassandra 查询中使用 ORDER BY 和 IN 语句
- excel - 使用电源查询删除不相关的数据
- android-studio - Flutter:IDE中缺少项目文件
- php - 错误:尚未在 php 中安装或启用 MongoDB PECL 扩展
- r - 如何在 RStudio 中将代码警告标记为不相关
- asp.net-core - 在部署期间为 vsts 发布提供客户端密码
- php - Json数据在laravel中一起返回
- r - 计算一组值在整个数据集中出现的次数