Search code examples
androidnfcandroid-4.0-ice-cream-sandwichandroid-4.2-jelly-beanapdu

Alternative way for EnableReaderMode - to work with Android API's lesser than 19 (ICS and Jelly Bean)..?


I'm currently working with an Android payment application which can communicate with ISO/IEC 14443-4 Smart Card using NFC.

To that purpose in my Activity I have enabled reader mode using

mNfcAdapter.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_B | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);

and overidded ReaderCallback 's onTagDiscovered() method to send and receive APDU commands between Android application and ISO/IEC 14443-4 Smart Card .

Since ReaderCallback and override onTagDiscovered() is available from API level 19 (KitKat),It's working fine with Android devices running on KitKat.

I would like to make my application work with Android ICS and Jelly Bean as well. Is there any alternative way or work around for this enable Reader Mode, to do APDU communication for ICS and JellyBean..?


Solution

  • No, there is no direct equvalent to enableReaderMode (in the way you are using it) before Android 4.4. However, you can achieve similar functionality by using the foreground dispatch system (see this answer on how to use the foreground dispatch).

    Nevertheless, note that there are some differences between using enableReaderMode(... FLAG_READER_NFC_B ... FLAG_READER_SKIP_NDEF_CHECK ...) and using enableForegroundDispatch(...):

    • The foreground dispatch will perform the NDEF check before passing the card to your app.
    • The foreground dispatch will poll for all technologies (even if you choose to handle only a specific technology with an appropriate intent filter).
    • There is a known bug with the tag precense check mechanism on Android devices based on the Broadcom NFC chipset that may interfere with your actual communication. This can only reliably be dealt with using the reader mode API.
    • You can only disable the tag scanning platform sounds using the reader mode API.