Facebook's Messenger, has a priority of 2147483647
, for their android.provider.Telephony.SMS_RECEIVED
broadcast receiver, declared in their manifest.
(It's sad we are forced to not follow the documentation's standards of max priority being 1000 because other apps make their own rules)
I understand that if my priority is also set to the ridiculously high level of 2147483647
that I'd have to have my app installed first to take precedence over any "ties". No problem, I made a screen to alert users what apps would probably need to be uninstalled then re-installed after my app to function properly.
But, here's the problem - Everything works fine, but as soon as the phone reboots, "Messenger" starts getting precedence over my app. I've looked all over the place to see how they could do this black magic. How do they do this? How do I get priority after reboot, when my app is installed first?
The only thing that has come to mind so far, is package names being ordered alphabetically on boot when registering broadcast receivers.
com. f acebook > com. s trikeforcezero
I was about to attempt to register my broadcast receiver on android.intent.action.BOOT_COMPLETED
but I have a feeling this won't work.
Messenger also has another "low priory broadcast receiver" for android.provider.Telephony.SMS_RECEIVED
set to -1
Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.
And the highest priority possible would be the maximum integer that android allows, which is (2^31 - 1). SYSTEM_HIGH_PRIORITY (1000): Applications should never use filters with this or higher priorities.
For sure:
If the user downloads your app before facebook, then your receiver will take precedence although both have the priority 2147483647. After a reboot, Facebook's receiver takes precedence although both have the same priority and yours was installed before. Therefore, for sure, the trick is in their BootReceiver.
Guesses:
In your Boot Receiver, try to add the following code:
ComponentName component; component=new ComponentName(this, SmsReceiver.class); getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); component = new ComponentName(this, SmsReceiver.class); getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
It might be useful to try to know whether your boot receiver is taking precedence over facebook's boot receiver. I am not sure if that is possible.
Finally, there is the process which can be differentiated in the manifest but am not sure if that can be handy in anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With