Android 4.2.1 SMS receiving and application receiving Sequence

Source: Internet
Author: User

Let's talk about the text message receiving process on Android, starting with rilj. After the processunsolicited method receives a new text message, events registered in basecommands are executed through the message mechanism.
The following code is executed in rilj: mgsmsmsregistrant. notifyregistrant (New asyncresult (null, SMS, null); so we only need to check where mgsmsmsregistrant has been registered and where new messages have been received. Only the gsmsmsdispatcher calls setonnewgsmsms () for registration. Because gsmsmsdispatcher implicitly inherits the handler class, we only need to check its handlermessage method and its parent class handlermessage method. Of course, we can also directly search for the registered event: event_new_sms, where to handle it, so as to find a way to handle the receipt of new text messages. We can find the handlemessage method of smsdispatcher. Find the method calling sequence as follows: dispatchmessage ()->
Dispatchnormalmessage ()-> dispatchpdus (). At the end of the message, an ordered broadcast ends. The method is sendorderedbroadcast ().
The above section describes the process of receiving text messages on the Framework side and finally notifies the application side through broadcasting. Let's start to explain why sendorderedbroadcast is sent here, instead of what we introduced when Android was just getting started. What are the differences between the two.
When declaring this method, the Code says: This broadcast only sends messages to one receiver at a time. All receivers receive broadcasts in order. The previous receiver can even transmit some data to the subsequent receiver. The previous receiver can even directly discard the broadcast, which will cause the subsequent receiver to no longer receive the broadcast. Summary: this sort of ordered broadcast is synchronous. It must be processed by the previous receiver before it can be sent to the subsequent receiver. Normal broadcast is asynchronous. The receiver of this broadcast has a sequence, that is, the receiver has a priority. We usually need to remember that these two kinds of broadcasts are sufficient for broadcasting.
Let's talk about priority settings. Let's look at the intent-filter in the configuration file. It turns out to have an Android: Priority = "integer" attribute. You can see that this setting sets the registrant's priority and emphasizes that this is only valid for Synchronous messages and not for asynchronous messages. The value range is-1000---1000, which must be an integer. The default value is 0. This attribute is not defined in native text messages, so the default value is 0. Currently, many apps can intercept harassing text messages. I guess these apps should have the highest priority during registration and will not continue to pass down after checking that they are spam text messages.
Add: when priorities are different, they are sorted by priority. What if the priorities of the two referers are the same? Android officially states that there are referers with the same priority, and the order in which they receive broadcasts is random.
Finally, let's take a look at the three concepts of knowledge: http://www.eoeandroid.com/thread-148381-1-1.html although Google said the highest priority is 1000, but from this post it seems that as long as there is no cross-border can be. :-(

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.