Android MMS: Deep understanding of Compose_android

Source: Internet
Author: User

The Composemessageactivity (hereinafter referred to as composer) in MMS is the most important component in the entire MMS, which is responsible for editing information, sending information, managing information, receiving information, and externally applying interfaces. There are a lot of classes and components associated with composer within MMS, almost all classes and components are associated with composer, and all operational processes for information begin with composer, and external composer are also exposed interfaces that can handle Intent.action_ Send and Intent.action_sendto and file types are audio/*,image/*,video/* and text/*.
Composer is a standard activity, its start-up process also passes through the OnCreate (), OnStart (), Onresume (), the destruction process passes through OnPause (), OnStop () and OnDestroy (). In addition, other operations are triggered by the user, or by other events, such as new information, database changes.
Initialization Process
The composer initialization process is done with the initialization UI, registering some receiver and listener, initializing conversation and workingmessage, querying for information, and so on. Among them, the initial initiation of conversation and Workingmessage is most important, because the UI and some operations depend on whether the conversation exists, as well as the number of messages and whether there are drafts. So here we're mainly talking about initializing conversation and Workingmessage.
The main processes of initialization are performed in the Initialize () function, and the following initialize () functions are mainly parsed. Initialize () The first thing to do is initialize the Workingmessage, create a new Workingmessage object Mworkingmessage, and then initialize intent based on bundle and conversation , this process is important because the conversation object contains all the important data for this session, including whether there are drafts, the number of messages, new or existing information that will affect the subsequent initialization work.
Initactivitystate () Mainly look at two parameters one is the incoming bundle the other is intent. It will give priority to see bundle, if the bundle object is not empty, will take out some state from the bundle, such as the recipient recipients, such as the exit status Exit_on_sent. The conversation get () method can be used to obtain the conversation object Mconversation according to the received recipient, and then Mworkingmessage read the relevant data from the bundle. In fact, the initialization here from bundle is corresponding to Onsaveinstancestate (), in Onsaveinstancestate () will save the recipients and let mworkingmessage write data to bundle, To preserve the state of the activity. Overall, the onsaveinstancestate is the state of the activity, and the Initactivitystate () is the state of the activity when the bundle is not empty.
If the bundle object is empty, then the relevant data is initialized from the intent, which is also the logic that most cases follow. The first is to check whether there are thread_id and address in the intent, and also to search for information about the addressee directly from the intent URI, in order to obtain conversation object mconversation with Conversation.get (). You will then try to get other information from intent such as the main sms_body of the message, the subject subject, and so on.
After Initactivitystate () is called, the Mworkingmessage and mconversation two objects should all be properly initialized. This is the time to deal with special intent:action_send and forward. First the processing of Action_send, which is an external interface, is sent through video/* when an external program wants to send text (text/*), pictures (image/*), Audio (audio/*) and video (intent.action_send) via MMS. A simple process for this Intent is to put the URI of the relevant file, usually in Intent.getextras (Intent.extra_stream), to load the URI as an attachment, or through the Intent.send_ Multiple to handle multiple attachments, but the logic is the same. Forward is forward_message when intent, take out the other two options, one is to forward the information of the URI, one is the theme subject and message body sms_body. Because both send and forward specify only the content of the information and do not specify the recipient, the Mconversation object does not have the actual content, and they all will be the same as the new information, except the content of the information.
In addition to action_send and forward information, all other information needs to be checked for drafts so that drafts can be loaded. The load draft is done by Mworkingmessage.loaddraft (), which checks the state of the mconversation and loads it from the database if a draft exists.
In this way, all the critical initialization operations have been completed, the data has been loaded, and the rest of the work is based on the data to initialize the UI, such as whether or not to display the letter-receiving edit bar.
Destruction Process
Composer's destruction to do only two things, one is to save the current edited information content, that is, save the draft, if any, and the other is through the onsaveinstancestate to save the state, but this is usually not used, It is only invoked when the composer is killed by the system and wants to reboot.
The work of saving drafts is mainly in OnStop (), so every time a user leaves the composer page, he walks into OnStop () and checks the relevant conditions to determine whether to save the draft. There are three conditions for saving drafts: information is content (mworkingmessage.isworthsaving (), content, subject, attachments are available), and the message has the correct recipient (not in the database), And there's composer waiting for other activity (this usually happens when you add a contact or add a draft, because you want to jump to another activity, so composer goes to OnStop (), but this time because the information is still in the editing, So you need to save the draft). If the above conditions are not met, discard the content (Mworkingmessage.discard ()), otherwise save the draft (Mworkingmessage.savedraft ()).
externally exposed interfaces
As with the open Interface for components in Android, composer's externally exposed interface is accomplished by handling intent, mainly two intent one is intent.action_send and the other is Intent.action_ SENDTO. The declaration of an interface is the Intentfilter in the Androidmanifest file. For processing, there are two places, one in Initactivitystate (), which will attempt to remove address, sms_body and subject from the intent, and also for Action_ Send requires significant processing handlesendintent () because the content that needs to be taken out of the intent is usually a multimedia file, and the multimedia file is removed and then added as an attachment to the information by Mworkingmessage.setattachment ().
There is also an interface for sharing contacts, and the way to share contacts is to send the information of the contact as the content of the message. The process is actually handled by the sharecontactsviasms in Contacts, which reads the contact information from the database and then spells a string and then uses intent as sms_body to send it to MMS.
Interaction with other components
Composer in the process of editing information, especially the process of editing MMS, you need to constantly interact with other components, such as adding pictures, adding audio, adding video or shooting pictures, shooting video and so on. For the selection of pictures, the choice of video is through interaction with the gallery application, send get_content intent to gallery,gallery will list pictures and videos for users to choose, when the user chooses, Gallery will pass the user's choice of the image or video URI to composer, then composer will use the UiR to add the attachment of the action. For audio is to interact with music applications, the logic is similar. The process is slightly different for taking pictures and shooting videos and recording audio. Taking pictures and shooting video in the request intent the path to specify the output URI is specified by Intent.extra_output. Camera writes the data in the specified URI, and composer reads the file directly from the URI (this is different from 2.3, and 2.3 is camera the file's URI in intent). Tempfileprovider is designed to manage the temporary storage of data while taking pictures and taking video. The URI passed to camera is "Content://mms_temp_file/scrapspace", which is managed by the Tempfileprovider, and is used by camera when camera () is to write the data OpenFile () , Tempfileprovider creates a temporary file that/sdcard/android/data/com.android.mms/mms_temp_file/scrapspace/on the external storage card. Temp.jpg,camera's pictures and videos are stored in this file. There are also methods in Tempfileprovider to manipulate the file, such as Tempfileprovider.renacescrapfile () to rename the. temp.jpg file into a. 3gp video. In addition to composer will use this tempfileprovider, in slideeditoractivity edit a slide will also use this temporary file, because the editing slides are also able to use camera to add pictures of the video.

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.