Search code examples
androidnfcpaymenthce

Android settings crash when trying to set default app (Host-based card emulation)


I'm trying to implement a Tap & Pay application and therefor need to communicate with a POS Terminal. In order to do so, the device needs to set my application as the default application for Tap & Pay functionalities. Whether trying to ask the user to set it programmatically or via settings app, android Settings crashes.

I figured it has something to do with the manifest file since the crash apparently occurs during the process of listing the tap & pay apps.

I've followed the instructions on host based card emulation I've found on the android developer page https://developer.android.com/guide/topics/connectivity/nfc/hce

manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wizypay.brantner.wizy">

<uses-feature android:name="android.hardware.nfc.hce" android:required="true"/>

<uses-permission android:name="android.permission.NFC" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_wizy"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_wizy"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".acitvities.LoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".acitvities.MainActivity" />
    <activity android:name=".acitvities.RegisterActivity"/>
    <service android:name=".services.HostCardEmulatorService" 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>
</application>
</manifest>

apduservice.xml:

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/servicedesc"
android:requireDeviceUnlock="false"
android:apduServiceBanner="@drawable/my_banner">

<aid-group android:description="@string/aiddescription"
    android:category="payment">
    <aid-filter android:name="A0000000043060"/>
    <aid-filter android:name="315041592E5359532E4444463031"/>
    <aid-filter android:name="325041592E5359532E4444463031"/>
    <aid-filter android:name="44464D46412E44466172653234313031"/>
    <aid-filter android:name="A00000000101"/>
    <aid-filter android:name="A000000003000000"/>
    <aid-filter android:name="A00000000300037561"/>
    <aid-filter android:name="A00000000305076010"/>
    ...
</aid-group>

</host-apdu-service>

I'm currently testing the application on a Google Pixel running Android 8.1.0

I hope someone has an idea what could cause the crash, thanks in advance!


Solution

  • There doesn't seem to be anything wrong with your code.

    I've found a list of Application Identifiers though https://www.eftlab.co.uk/index.php/site-map/knowledge-base/211-emv-aid-rid-pix

    After playing around a bit I've found out that android set a limit to the possible amount of AIDs that can be registered, which seems to be at 260. Maybe you added too many?