Search code examples
androidnfcandroid-lifecycleapduhce

Is it necessary to have the payment app running to do HCE transactions?


I'm writing an NFC payment app.

I know I can do NFC transactions using HCE whether the application is opened or not. But I don't know if it is necessary to have the app running on the background.

Is it necessary to have the payment app running in the background?


Solution

  • Yes, your app needs to run in the background during a HCE transaction.

    However, Android will automatically take care of this. All you need to do is to register your HostApduService class implementation and its list of AIDs in the manifest of your app. Upon selection of any of the declared AIDs, Android will automatically lookup the corresponding HostApduService implementation, start (actually bind) it if its not already started, and pass APDUs to it.

    Note that you could even have a payment app that does not have any activity at all, so there is no need for any activity of your app to be started and hidden in the background for HCE to work.