androidandroid-intentnfcndefnfc-p2p

What does enableForegroundDispatch and disableForegroundDispatch do?


I read the documentation and I don't quite understand what either do. Considering Android made the puzzling decision that we now need to use Android Beam to send data from 1 one phone to another and there is no way to simultaneously send data from both to both, I don't see the use.

Can't I just call setNdefPushMessage on one phone, and have an onNewIntent callback in the other phone which does something if NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction()) is true?

What is the point of enableForegroundDispatch and disableForegroundDispatch?


Solution

  • enableForegroundDispatch gives your current foreground activity priority in receiving NFC events over all other actvities.

    For instance, consider the following example:

    Some more things: