What does enableForegroundDispatch and disableForegroundDispatch do?

I have read the documentation and I am not quite sure what to do. Considering Android has made a cryptic solution that we now need to use Android Beam to send data from one phone to another, and there is no way to send data from both to both at the same time, I see no use.

Can't I just call setNdefPushMessage

one phone and do a callback onNewIntent

on another phone that does something if NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())

true?

What is the point enableForegroundDispatch

and disableForegroundDispatch

?

+3


source to share


1 answer


enableForegroundDispatch

gives the current priority of foreground activity when receiving NFC events for all other activities.

For example, consider the following example:

  • Your activity and another activity (either from the same application or from a different application) have registered an intent filter for the same NDEF record type in the manifest.

  • As the first entry, your device receives an NDEF message containing this entry type.

  • If the current foreground activity has not been logged to the foreground dispatching system, an action selection list will be shown and the user can choose between the two actions.

  • If the current foreground activity, however, has registered with the foreground dispatch system (to receive this record type), it will take precedence over all explicitly registered intent filters and receive an NDEF message without any additional user interaction.



A few more things:

  • An Android Application Record (AAR) app, if added to an NDEF message, will have a similar effect, as it will cause the NDEF message to be delivered only to the specific application.

  • If the NDEF message contains an AAR for another application, you can still use the foreground dispatching system to force the NDEF message to be sent to your application. Thus, the foreground dispatcher takes precedence over the AAR.

  • Note that the foreground dispatching system is used not only for peer to peer communication but also for reading NFC tags. In this case, there are tags that do not contain NDEF messages and, therefore, are significantly more likely to result in multiple activities being registered for the same tag type. So, in this case, its again useful to give priority to your activity over any other activities that are registered for the same tag type.

+8


source







All Articles