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.
Michael Roland
source share