Android MMS topic: receiving information process

Source: Internet
Author: User

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.

Receive SMS

The upper-layer application processes the broadcast event sms_received_action, which is sent by frameworks to notify 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, place the refreshed thread 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.


Receiving of MMS

The receiving process of MMS is slightly different from that of SMS. The application is responsible for downloading the MMS information from the mmsc Multimedia Messaging Service Center. The general process is that frameworks sends a text message to inform the application of a MMS Message, which contains some information such as the expiration date, the sender's mobile phone number, and the mms url, then the application automatically retrieves the MMS content specified by the URL through HTTP. The specific process is as follows:

Telephony frameworks sends an intent: Android. provider. telephony. intents. wap_push_received_action = "Android. provider. telephony. wap_push_received" message to the upper-layer application. This intent will contain a "data" byte array (through byte [] DATA = intent. getbytearrayextra ("data"). This byte array describes some information about the mms. It is a notificationind, which contains some information about the MMS, such as the mobile phone number of the sender, the contentlocation (URL) of the MMS ). Then, the application determines how to proceed.

In MMS, transaction. pushreceiver. java receives wap_push_received_action. After receiving the intent message of the MMS, it performs some preprocessing, retrieves the data field, parses it into genericpdu using the PDU tool, and then converts it to icationicationind, write it to the database, and then start transactionservice for further icationication_transaction processing. At the same time, the URI of notifind IND is also passed.

Transactionservice is triggered. In its onstartcommand, the intent sent by pushcycler is placed in its messagequeue, and icationication_transaction is processed when transaction_request is processed in handler. handlemessage. First, load some default MMS-related configuration information, mainly mmsc, proxy and port. These are carrier-related information and can be changed through the APN settings. Transactionservice uses the URI of icationicationind sent by pushreciver and the loaded configuration information transactionsettings to construct a notificationtransaction object. Transactionservice checks the two queues in the queue, adds the queue to the pending queue, or directly processes the queue (adds the queue to the processing queue). The processing also directly calls icationicationtransaction. Process ().

The notificationtransaction process () method inherits from the parent class transaction. It simply starts a new thread and returns, in this way, the service can process other transaction requests.

In the thread, first load some configuration information from downloadmanager and telephonymanager, whether the MMS is set to auto retrieve, and whether telephony is set to data_suspend ), then, different measures are taken to retrieve the expiration date of the MMS from icationind ind. If the configuration is not to retrieve data (more specifically, it is not to retrieve data now), mark the downloadmanager status as state_unstarted first, and then send a policy message to mmsc.
Response indication, and then the processing is completed. The function returns and the notification processing process of MMS ends here. You can manually download the MMS by using other methods through the UI, which will be discussed in detail later.

If it is set to automatic acquisition or data transmission is smooth, mark the downloadmanager status as start_downloading and start to download MMS data. MMS is obtained through contentlocation (URL) from http to MMs. First, call the parent method getpdu (), pass in the mms url, and finally call the httpconnection method of httputils to send an http get request. mmsc will return the MMS data as the return value of getpdu. We get a byte array. We need to use the PDU tool to parse it into genericpdu, then use pdupersister to write it into the database, and then update the MMS size to the database, the receiving of a MMS Message is complete. The rest is that, because the MMS data has been obtained, You need to delete the previous notification information (notifind IND), update the related status, and return notify to mmsc.
Response indication, end processing. Because the database has changed, the UI will receive the contentchanged event, refresh the UI list, and the new information will be displayed.


As mentioned above, if the MMS configuration is set to not automatically obtained, after the UI is refreshed, the MMS notification will be displayed: expiration date, MMS size, etc., and a "Download" button will be provided. You can click the button to download the MMS content. After you click the button, transactionservice is started to package the URI of the MMS notification and retrieve_transaction request into an intent and send it to transactionservice. Transactionservice, like processing other transactions, is put into its own messagequeue, then load the default transactionsettings, build the retrievetransaction object, and then process and call retrievetransaction. Process ().

Retrievetransaction is also inherited from transaction, and its Process () is also used to create a thread and then return. In the process, it first uses the PDU tool to load the multimedia notification (MMS) from the database according to the URI, obtains the expiration date of the MMS from icationind ind, and checks the expiration date. If the MMS has expired, send y response indication to mmsc. Mark the downloadmanager status as start download. If the MMS has expired, mark the transaction status as failed, return, and end the processing process. If everything is normal, getpdu () is used to obtain the MMS content from the contentlocation (URL) of the mms. It is obtained through HTTP through httputils. httpconnection () and a byte array is returned. Use the PDU tool to parse the byte array and obtain the genericpdu. check whether it is a new message or duplicate information. If it is repeated, mark it as failed, return it, and end the processing. If it is a new message, first write the genericpdu into the database with pdupersister, update the information size and contentlocation (URL) to the database, where all the MMs have been obtained. Next, send the received confirmation message to mmsc, mark the processing status as successful, and end the processing. At this time, the UI should listen to database changes and refresh. New information should be displayed to users.


Summary: similar to sending information, a database also plays an important role in receiving information. After receiving the information, it parses the information and writes it to the database, which is different from sending, the received information is not in that many States. Once the information is written to the database, it means that the information is successfully received. The UI only listens to changes in the database, and immediately refreshes the display information.

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.