Welcome to our new developer portal! Use the "Ask" button to chat with our AI Agent.
For the complete documentation index, see llms.txt. This page is also available as Markdown.

1. Implement HCE service

Overview

NFC Wallet SDK supports Android Host Card Emulation (HCE). It allows NFC card emulation and exchange APDUs with a POS terminal over NFC.

For details, see Android documentation: Host-based card emulation overview.

To continue, first implement an HCE service as described in this section.

After you register the service, verify it appears under Tap and Pay in Android settings.

SDK integration

Extend AsyncHCEService

To handle contactless payments, enable APDU processing by extending AsyncHCEService.

You do not need to override any methods.

Use overrides only if you want to log or customize APDU handling.

public class MyHCEService extends AsyncHCEService {

    // Overriding 'processCommandApdu' is optional
    // Digital wallet application can capture APDU processing time.
    @Override
    public byte[] processCommandApdu(byte[] inputApdu, Bundle bundle) {
        // Return the SDK value (always 'null').
        // APDU processing is asynchronous.
        // The SDK automatically sends response APDU to the POS terminal.
        return super.processCommandApdu(inputApdu, bundle);
    }

    // Overriding 'onApduResponse' is optional
    // Digital wallet application can inspect or override the response APDU.
    @Override
    public boolean onApduResponse(final byte[] inputApdu, final Bundle extras, final byte[] responseApdu){
        // Digital wallet application can log responseApdu.

        // If you want to override the response and reply to the POS terminal:
        // 1. modify the responseAPDU
        // 2. sendResponseApdu(modifiedResponseApdu);
        // 3. return true; it tells the SDK the response is already sent.

        // Otherwise, return false and let the SDK send responseApdu.
        return false;
    }
}

NFC Wallet SDK suspends APDU processing when authentication is required.

APDU processing resumes after authentication succeeds, is aborted, or the HCE service is deactivated.

Register the service in AndroidManifest.xml

Register your HCE service (the class that extends AsyncHCEService) as HOST_APDU_SERVICE in your manifest.

Create apduservice.xml in res/xml to declare the supported AIDs.

Declare supported AIDs

Create apduservice.xml in res/xml.

Declare the PPSE AID and the payment network AIDs you support.

In the example above:

  • The required PPSE AID is:

    • 325041592E5359532E4444463031

  • The Mastercard AIDs are:

    • A0000000041010

    • A0000000043060

    • A0000000042010

  • The Visa AIDs are:

    • A0000000031010

    • A0000000980840

    • A0000000032020

    • A0000000032010

The AID list depends on your NFC Wallet program. Confirm the list with your payment network representative.

Verify Tap and Pay settings

After you register the HCE service in AndroidManifest.xml, it appears under Tap and Pay in Android settings.

To verify:

  1. Open Settings on the device.

  2. Go to Tap and Pay.

  3. Confirm your application appears in the list.

Android settings showing the application listed under Tap and Pay.

Last updated

Was this helpful?