user8181050 user8181050 - 7 days ago 4
Android Question

BroadcastReceiver which allows call to proceed, but prevents other receivers from processing it?

I have an App which is a BroadcastReceiver and which processes

NEW_OUTGOING_CALL
intents. There are also other apps on my phone that are registered as receivers for these intents, but mine is registered with a higher priority intent filter, so my BroadcastReceiver gets to see the intents first.

I would like to programmatically be able to prevent any other registered BroadcastReceiver for
NEW_OUTGOING_CALL
from processing these intents, but I would like to allow the phone call to proceed. Is this possible?

Answer

I don't think you can actually do what you want to do. The documentation for this action describes pretty clearly how the system expects this broadcast to be handled:

For consistency, any receiver whose purpose is to prohibit phone calls should have a priority of 0, to ensure it will see the final phone number to be dialed. Any receiver whose purpose is to rewrite phone numbers to be called should have a positive priority. Negative priorities are reserved for the system for this broadcast; using them may cause problems.

If you want to see the number first, you can do that (with a higher priority), but then you have to live with other receivers seeing it after you do. Alternatively, you can see the number last (by lowering your priority to 0), but then you have to live with other receivers seeing the number before you do.

Note that another person suggested aborting the broadcast. Not only does this not make sense since the system needs the result of the broadcast, it also is stated explicitly in the documentation not to abort this broadcast.

Any BroadcastReceiver receiving this Intent must not abort the broadcast.