What is the difference between enableReaderMode and enableForegroundDispatch?

I found two approaches for the Android application to detect and process NFC tags:

  • NfcAdapter.enableReaderMode(activity, callback, flags, extras) , and then get the tag information in the callback.

  • NfcAdapter.enableForegroundDispatch(activity, intent, filters, techLists) , and then get the tag information in the onNewIntent(intent) method.

I am currently using the second approach, however, I recently discovered the enableReaderMode approach and enableReaderMode wondering if it is better to use it to handle NFC tags.

So what is the difference between enableReaderMode and enableForegroundDispatch ?

+8
android tags nfc hce android-beam
source share
2 answers

Foreground Dispatch System

An underground dispatch system ( NfcAdapter.enableForegroundDispatch() ) exists since Android 2.3.3 (which is basically the beginning of Android NFC). Therefore, this method is supported on all Android devices with NFC capabilities.

The foreground scheduling system is used to provide the activity that is currently in the foreground priority when processing NFC detection events (i.e., detected NFC tags and NDEF messages received from peer devices). This means that even if another application is registered (using the intent filter in AndroidManifest.xml) for a certain type of tag or NDEF data, the NFC event will still be passed to the foreground action instead of this other action. Therefore, this method does not change the way Android listens for NFC devices (NFC tags, P2P devices), it changes the priority when working with detected devices.

Reader Mode API

The reader mode API ( NfcAdapter.enableReaderMode() ) was introduced in Android 4.4. Therefore, not all Android devices with NFC capabilities support this method.

Unlike the foreground dispatch system, the reader mode API changes the way Android listens for NFC devices. The reader mode API disables peer-to-peer mode. This, for example, allows you to detect the card emulation mode of other devices that have peer-to-peer mode and the card emulation mode that are activated simultaneously (as is the case with Android HCE). (Typically, such a device will be detected as a peer-to-peer device, and the Android application will not be able to access the card emulation features.)

In addition, you can change certain parameters of the NFC reading mode, for example. You can

  • identify the tag technologies that an NFC reader reads,
  • determine the interval during which Android checks to see if the tag is present by sending a specific sequence of commands to the tag and checking if a response is received,
  • stop Android from automatically sending commands to a tag to check if the tag contains an NDEF message,
  • stop Android from playing sound when tags are detected.
+12
source share

enableReaderMode : Limit the NFC controller in read mode when this action is in the foreground.

enableForegroundDispatch : This will give priority to foreground activity when sending the detected tag to the application.

This way you can use both the same goals as reading / writing a tag. enableReaderMode used by Android phones in conjunction with the Broadcom NFC controller because there is an error in validation verification. As far as I know, only enableReaderMode can evade this by increasing EXTRA_READER_PRESENCE_CHECK_DELAY .

+4
source share

All Articles