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;
}
}Register the service in AndroidManifest.xml
Register your HCE service (the class that extends AsyncHCEService) as HOST_APDU_SERVICE in your manifest.
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:
A0000000041010A0000000043060A0000000042010
The Visa AIDs are:
A0000000031010A0000000980840A0000000032020A0000000032010
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:
Open Settings on the device.
Go to Tap and Pay.
Confirm your application appears in the list.

Last updated
Was this helpful?