5

在 NFC HCE 应用程序中调整以使其在设置 NFC Tap and Pay 下可见的关键是什么

以下代码为应用程序返回 true,因此它能够付款:

boolean isDefault = CardEmulation
                .getInstance(NfcAdapter.getDefaultAdapter(this))
                .isDefaultServiceForCategory(
                        new ComponentName(this, MyPaymentService.class),
                        CardEmulation.CATEGORY_PAYMENT);

清单中的服务声明:

<service
    android:name="my.package.MyPaymentService"
    android:exported="true"
    android:permission="android.permission.BIND_NFC_SERVICE" >
    <intent-filter>
        <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

    <meta-data
        android:name="android.nfc.cardemulation.host_apdu_service"
        android:resource="@xml/apduservice" />
</service>

服务:

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:requireDeviceUnlock="true" >

    <aid-group
        android:category="payment"
        android:description="@string/paymentGroup" >
        <aid-filter
            android:name="325041592E5359532E4444463031"
            android:description="@string/ppse" />
        <aid-filter
            android:name="A0000000041010"
            android:description="@string/mastercard" />
        <aid-filter
            android:name="A0000000031010"
            android:description="@string/visa" />
        <aid-filter
            android:name="A000000003101001"
            android:description="@string/visa" />
        <aid-filter
            android:name="A0000002771010"
            android:description="@string/interac" />
    </aid-group>

</host-apdu-service>

我错过了一些东西,但不知道该放什么以及放在哪里。

谢谢。

4

3 回答 3

9

为了在点击付款菜单中显示,HCE 应用程序必须提供横幅图形。android:apduServiceBanner您可以使用以下属性将图形包含到 host-apdu-service XML 中:

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:requireDeviceUnlock="true"
    android:apduServiceBanner="@drawable/servicebanner">

    <aid-group android:category="payment"
               android:description="@string/paymentGroup" >
        <aid-filter ... />
    </aid-group>
</host-apdu-service>

服务横幅应该是尺寸为 260 x 96 像素的图形文件(例如 .png 文件)。

于 2014-06-11T11:12:58.013 回答
3

附加信息 - 如果您忘记清单中的以下两行,该应用程序也不会显示在“点击付款”菜单中。

<uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
<uses-permission android:name="android.permission.NFC" />
于 2017-12-13T09:44:25.857 回答
2

使用这个 Google 示例项目,我尝试添加 @Michael Roland 的建议(例如添加 android:apduServiceBanner、类别和描述)。

结果,图形显示在触碰付款设置屏幕中,而不是文本中。我记录了示例项目的问题,但不希望有任何解决方案。

当前的解决方法是创建一个 apduServiceBanner 可绘制对象,该可绘制对象具有内置到可绘制对象中的文本。

于 2017-09-14T19:29:08.503 回答