Implementing NFC Payment (HCE) via Android App

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Implementing NFC Payment (HCE) via Android App
Complex
~5 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1050
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

NFC Payment (HCE) Implementation via Android Application

Host-based Card Emulation — technology allowing Android app to masquerade as contactless card without physical SE (Secure Element). Sounds simple. Actually — implementation of ISO/IEC 7816-4 over NFC with APDU commands, service lifecycle management, AID registration and payment system certification. Most commands like SELECT AID and GET PROCESSING OPTIONS must be implemented manually.

Main Challenge: APDU Dialog with Terminal

When POS terminal "sees" phone, it sends series of APDU commands. Standard EMV Contactless scenario starts with:

00 A4 04 00 07 A0 00 00 00 03 10 10 — SELECT PPSE

App must respond with correct FCI containing AID name. Then terminal selects specific app (SELECT AID), requests transaction parameters via GET PROCESSING OPTIONS, reads records via READ RECORD. Each response — strictly per EMV Book 3 and Book C-2.

One byte error in TLV structure — terminal returns "Card not accepted" with no details in app logs. Debugging requires NFC sniffer (e.g., ACR122U + libnfc + Wireshark) or hardware protocol analyzer.

AID Registration and Conflicts

Each HCE app registers AID in AndroidManifest.xml via <host-apdu-service>. Multiple apps with one AID — Android shows disambiguation dialog. For proprietary AIDs manageable. For standard ones (Visa: A0000000031010, Mastercard: A0000000041010) conflict with banking apps — user must choose every time.

Solution — register proprietary AID in range F0xx..., coordinate with processor, configure terminal to accept. Or use HCE_PAYMENT category with preinstalled AID and properly handle conflicts via CardEmulation.setPreferredService().

HCE Service Architecture

HostApduService — a Service Android launches when NFC field appears. Main method — processCommandApdu(), called on main thread. Blocking it forbidden: if response doesn't arrive within ~500 ms, terminal disconnects.

Typical structure:

class PaymentHceService : HostApduService() {

    private val apduProcessor = ApduProcessor()

    override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
        return apduProcessor.process(commandApdu)
    }

    override fun onDeactivated(reason: Int) {
        apduProcessor.reset()
        // reason: DEACTIVATION_LINK_LOSS or DEACTIVATION_DESELECTED
    }
}

ApduProcessor — state machine holding current transaction state: PPSE selected, AID selected, GPO state. State resets in onDeactivated. Critical: not resetting after DEACTIVATION_LINK_LOSS — next transaction starts with wrong state.

Token Security

Cannot store real PAN data in app. Modern scheme — dynamic tokens: server issues single-use cryptogram for each transaction. App requests token early (when opening payment screen), stores encrypted in EncryptedSharedPreferences or Android Keystore, transmits to terminal in READ RECORD response.

Token lifetime — usually 30–60 minutes or one transaction. On expiry — app requests new before next transaction, not during processCommandApdu (no time for network request).

Testing Without Real POS Terminal

For development and CI:

  • ACR122U + PC/SC — USB NFC reader, emulates terminal on PC, can script APDU sequences
  • Mastercard PayPass Test Tool — official EMV response validation
  • EMV-Co contactless test cases — certification scenario set

Without passing EMV-Co test cases, can't get access to real Visa/Mastercard terminals. Separate project phase.

Process and Timeframes

Work divided into phases: design APDU dialog for specific processor → implement HCE service → integrate with backend tokenization → test on real terminals → prepare certification documentation.

Minimum PoC with custom AID — 2–3 weeks. Full integration with EMV certification — from 2 months. Exact timeframes after processor requirements and tokenization scheme study.