Android SMS module analysis (4) sending and receiving of MMS messages

Source: Internet
Author: User

Analysis of sending and receiving MMS text messages:

I. Message sending:

Com. Android. mms. Data. workingmessage. Java class

Send () function:

Public void send (){...... if (requiresmms () | addresscontainsemailtomms (Conv, msgtxt) {// MMS slideshow. prepareforsend (); New thread (New runnable () {public void run () {sendmmsworker (Conv, mmsuri, persister, slideshow, sendreq );}}). start () ;}else {// SMS new thread (New runnable () {public void run () {presendsmsworker (Conv, msgtext );}}). start ();......}

Prapareforsend (). Make sure there is slidshow, that is, the actual content. Make sure that the text has been copied. Ensure the title. According to the Message classification, if it is a short message, directly start a thread, run the presendsmsworker function, send the short message; if it is a MMS, first run prapareforsave to ensure the text information, then start a thread and run the sendmmsworker function separately. Whether it's text message or MMS, even if one of the worker functions is successfully sent. Finally, modify the recipient cache and reset the flag. The process is complete.

The presendsmsworker function is called before sending text messages. The sendsmsworker function is added to the presendsmsworker function.

private void sendSmsWorker(String msgText, String semiSepRecipients, long threadId) {......  MessageSender sender = new SmsMessageSender(mContext, dests, msgText, threadId);sender.sendMessage(threadId);......      }

Smsmessagesender. Java class, which implements the messagesender interface under MMS/transaction. This interface sendmessage and returns a Boolean value. If MMS is sent, true is returned. If SMS is sent, false is returned.


Of course, there are differences between the SMS sending process for single-card mobile phones and dual-card dual-waiting mobile phones (the SMS receiving process is the same and the process is relatively simple ), the specific process is illustrated directly using UML diagrams:

Message sending and receiving sequence diagram:

Send SMS

The sequence of sending a single-card SMS message is shown in Figure 1.1:


The sequence 1.2 of Two-card SMS messages is shown in the following figure:




Ii. receive text messages

Information receiving is done at the underlying layer. When a new information is received at the underlying layer, the upper-layer application is notified in intent mode, the information is also included in intent, and the information intent supported by Android is defined in Android. provider. telephony. intents.

For upper-layer applications, messages are sent to handle broadcast events.Sms_received_actionIt is sent by frameworks to inform the upper layer that a new SMS has been received. In MMS, it is handled by privilegedsmsreceiver. It receives sms_received_action (Android. provider. telephony. intents. sms_received_action = "android. provider. telephony. sms_received) will start smsreceiverservice for specific processing.

Smsreceiverservice first checks the type of the SMS. If it is a class0 SMS, it is directly displayed in the GUI without any other processing, that is, it is not stored in the database, and do not do notification in the notification bar.

For other text messages, existing messages are replaced or inserted as new messages. The principle is that if the existing text messages in the database are the same as the original address and protocol ID of the new SMS, they will be replaced with the new SMS, otherwise, it will be inserted as a new text message.

Specific replacement process: generate a contentvalues with the new text message, and then query the contentvalues with the text message address and protocol ID as the condition. If the information is found, replace the text message. Otherwise, it will be stored.

The storage process is to form a cotentvalues, and then take out the thread ID and address of the SMS. The address must be synchronized with the contact database to ensure that the address is recognizable. If the thread ID is not valid, use the synchronized address to re-generate the thread ID five times. Then, refresh the thread
Put the ID in contentvalues and insert contentvalues into the database. If you want to store the information to the SIM card, you also need to call smsmanager to copy the information to the SIM card. Calculate the SMS size and update it to the database. Delete expired SMS messages and SMS messages that have exceeded the limit, and then return the inserted SMS Uri.

Finally, use URI to go to statusbar for notification for the replaced or inserted text message.

The GUI can also get new text messages when refreshing the list, because the text messages have been stored in the database.


The message receipt sequence 1.3 is shown in the following figure:

Related Article

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.