San*_*dak 14 android nfc android-pay
嗨,我正在研究用于NFC支付的Android应用程序.
Android设置中有一个选项可以使用打开的应用程序而不是默认应用程序.例如,当我将默认应用程序设置为Android Pay并且在付款之前打开我的应用程序时 - 我想使用我的应用程序进行付款而不是默认应用程序.见图像波纹管.
我测试了它,但遗憾的是我用Android Pay而不是我在前台运行的应用程序付款.
我没有在文档中找到任何单词,如果我必须添加一些东西来清单,注册一些东西等.?
我service跟intent filter和meta data我的清单,并当应用程序被设置为默认的付款,这是正常工作:
<service
android:name="com.example.MyWalletHceService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice"/>
</service>
Run Code Online (Sandbox Code Playgroud)
添加apduservice xml内容:
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:apduServiceBanner="@drawable/ic_logo_nfc_system"
android:description="@string/nfc_service_title"
android:requireDeviceUnlock="false">
<aid-group
android:category="payment"
android:description="@string/nfc_aid_desc">
<!-- Following is a PPSE AID. You must always include this AID in order for payments to
work-->
<aid-filter android:name="@string/aid_number"/>
<!-- Following AID list is specific to the application requirements.
If your application supports the type of card that these AID represents,
you must include those AID in your configuration file -->
<aid-filter android:name="@string/aid_mc_filter"/> <!-- Mastercard DEBIT/CREDIT -->
</aid-group>
Run Code Online (Sandbox Code Playgroud)
所以我终于找到了解决方案!
您必须在当前前台活动中使用setPreferredService(Activity,ComponentName).建议在内部调用它,onResume()并且一旦活动不在前台(也就是调用它的好地方),也不要忘记调用unsetPreferredService(ActivityonPause()).
还有一件事: 在API 21中添加了setPreferredService(Activity,ComponentName)和unsetPreferredService(Activity),因此请确保不要从旧API调用它们.
| 归档时间: |
|
| 查看次数: |
1296 次 |
| 最近记录: |