broadcast is divided into 2 kinds, disorderly broadcast and orderly broadcast. Can be understood as hashing and queue broadcasts.
first out of order broadcast, can not be interrupted, the distribution mechanism is a bit like hash send. The transmission of this broadcast is: Context.sendbroadcast
This broadcast is not interrupted, please see the API description.
second, an orderly broadcast, can be interrupted.
This kind of broadcast, in my understanding there may be a big bug, SMS this broadcast of the sending bug is now used by QQ and 360, may be revised in later versions.
it is sent in a priority order, that is, by some sort of messagequere queue, where any broadcast recipient in the queue can terminal the broadcast, causing the member after it to not receive the broadcast.
let's start by looking at how this queue is formed: (the following is hypothetical + test validation, pending code validation)
Suppose our broadcast priority level is set to: 2147483647 (note: Maximum int integer)
First, dynamic registration has the highest priority level
Second Static registration
in Dynamic registration
highest first dynamic registration priority level
in the static registration
first installed program, static registration priority highest level (note: Install APK will parse Af.xml, put it into queue)
Note that the installation here refers to the ADB install xxx.apk or the mobile phone installation application.
then the ADB push is applied to other directories
The possible reason is that the mobile phone query application will go to the specific directory to resolve the application, so broadcast registration will appear this difference. Will adb push to system/app be higher than the installation priority? This has yet to be verified by you, I have not verified it yet.
and then it's all in the installed app.
highest priority for first installation
OK above is my analysis of the priority level of the ordered broadcast.
Anti-compilation 360 source will find that he first statically registered broadcast receiver set a priority order of 2147483647, and then start a service in the broadcast, in the service registered a priority order of 2147483647 of the same broadcast receiver.
It's easy to intercept text messages without using the same implementation.
OK, let's do an experiment in the same way now:
first write an application, register a boot to complete the broadcast receiver.
<receiver android:name= ". Mybrocast "android:permission=" Android.permission.BROADCAST_SMS "> <intent-filter android:priority=" 2147483647 "> <action android:name=" Android.provider.Telephony.SMS_RECEIVED "/> </ intent-filter> <intent-filter android:priority= "2147483647" > <action android:name= " Android.intent.action.BOOT_COMPLETED "/> </intent-filter></receiver>
Then start a service immediately after the broadcast recipient receives the message
Public void OnReceive (Context context, Intent Intent) { log.v ("mybrocast.onreceive", "TESTTTTTTTTTTTTT"); if (Intent.getaction (). Equals (intent.action_boot_completed)) { Intent service=New Intent ( Context, MyService. class ); Context.startservice (service); }
Then the service re-registers a receiving message broadcast recipient, priority 2147483647
New Intentfilter ("Android.provider.Telephony.SMS_RECEIVED"); Localintentfilter.setpriority (2147483647); New mybrocast (); = MyService; LOG.V ("mybrocast.onreceive", "OnCreate"); = Registerreceiver (Localmessagereceiver, Localintentfilter);
This restart phone is OK, you can also let 360,qq depressed.