Android MMS topic: compose details

Source: Internet
Author: User

Composemessageactivity (composer) in MMS is one of the most important components in mms. It is responsible for editing information, sending information, managing information, receiving information, and interfaces with external applications. In MMS, many classes and components are associated with composer, and almost all classes and components are associated with composer. All operation flows on information start with composer; external composer is also a public interface that can process intent. action_send and intent. the action_sendto file type is audio/*, image/*, video/*, and text /*.
Composer is a standard activity. Its startup process also goes through oncreate (), onstart (), onresume (), and the destruction process goes through onpause (), onstop () and ondestroy (). In addition, other operations must be triggered by the user or by other events, such as new information and database changes.

Initialization Process

The initialization process of composer involves initializing the UI, registering some referers and listener, initializing conversation and workingmessage, and querying information. Among them, the initial conversation and workingmessage are the most important, because the UI and some operations depend on the existence of conversation, the number of messages, and whether there are drafts. Therefore, we will mainly discuss the initialization of conversation and workingmessage.
The main initialization process is carried out in the initialize () function, and the initialize () function is also parsed here. Initialize () the first thing to do is to initialize workingmessage and create a new workingmessage object mworkingmessage. Then, it is important to initialize conversation Based on intent and bundle, because the conversation object contains all the important data of this session, including whether there are drafts, the number of information, whether it is new information or existing information, this information will affect subsequent initialization work.
Initactivitystate () mainly refers to two parameters: one is the passed bundle and the other is the intent. It checks the bundle first. If the bundle object is not empty, some status will be retrieved from the bundle, such as the recipient recipients, such as the exit status exit_on_sent. According to the receiver, you can use the get () method of conversation to obtain the conversation object mconversation. Then, mworkingmessage will read the relevant data from the bundle. In fact, the initialization from bundle corresponds to onsaveinstancestate (). In onsaveinstancestate (), recipients is saved and mworkingmessage is written to the bundle to save the activity state. In general, onsaveinstancestate stores the activity state, while initactivitystate () restores the activity state when bundle is not empty.
If the bundle object is empty, the related data is initialized from the intent, which is also the logic in most cases. First, check whether there are thread_id and address in the intent, and also directly search for information about the recipient from the intent Uri, so that the conversation object mconversation can be obtained using conversation. Get. Then, other information such as the message body sms_body and topic subject will be obtained from the intent.
After initactivitystate () is called, both mworkingmessage and mconversation objects should be correctly initialized. At this time, we need to deal with the special intent: action_send and forward. Processing action_send is an external interface. When an external program wants to send text (text/*), image (image/*), and audio (audio/*) via MMS /*) and the video (Video/*) will use intent. send by action_send. The processing of this intent is simply to put the URI of the relevant file, usually in the intent. getextras (intent. in extra_stream), you can load the URI as an attachment or use intent. send_multiple to process multiple attachments, but the logic is the same. When forward is an intent with forward_message, the other two options are taken out simultaneously. One is the URI of the information to be forwarded, and the other is the topic subject and the message body sms_body. Because both send and forward specify only the content of information but not the recipient, the mconversation object has no actual content. They are the same as the newly created information, but only have information.
Except for the information of action_send and forward, you need to check whether there is a draft for other information to load the draft. A draft is loaded by mworkingmessage. loaddraft (). It checks the status of mconversation. If a draft exists, it is loaded from the database.
By now, key initialization operations and data loading have been completed. The rest of the work is to initialize the UI based on the data, such as whether to display the email receiving edit bar.

Destruction Process

The destruction of composer only requires two tasks: one is to save the content of the currently edited information, that is, to save the draft, if any; the other is to save the status through onsaveinstancestate, but this is usually not used. It is called only when the composer is killed by the system and wants to be restarted.
The work of saving the draft is mainly on onstop (), so whenever the user leaves the composer page, the onstop () will check the relevant conditions to determine whether to save the draft. There are three conditions for saving the draft: the information has content (mworkingmessage. isworthsaving (), with content, themes, and attachments), and the information has the correct recipient (not in the database ), in addition, composer is waiting for other activities (this usually occurs when you add a contact or add a draft, because you want to jump to another activity, composer will also go to onstop (), however, because the information is still being edited, you need to save the draft ). If the preceding conditions are not met, the message content (mworkingmessage. Discard () is discarded. Otherwise, the draft (mworkingmessage. savedraft () is saved ()).

Open APIs

Similar to the public interface used by components in Android, composer is also implemented by processing intent. The two intent interfaces are intent. action_send, and the other is intent. action_sendto. The Declaration of the interface is the intentfilter in the androidmanifest file. For processing, there are two places. One is in initactivitystate (), the address, sms_body and subject will be retrieved from the intent; in addition, handlesendintent () needs to be obviously processed for action_send (), because the content of information to be retrieved from intent is usually a multimedia file, the multimedia file is taken out and then mworkingmessage is used. setattachment () is added as an attachment of information.
Another interface is to share a contact by sending the contact information as text message content. This process is actually handled by contacts's internal contactsviasms. It will read the contact information from the database, splice it into a string, and send it to mms as the sms_body using intent.

Interaction with other components

Composer needs to constantly interact with other components during information editing, especially during MMS editing, such as adding images, adding audio, adding videos, taking pictures, and shooting videos. For image selection, the video is used to interact with the gallery application, and the intent of get_content is sent to gallery. Gallery lists the images and videos for users to choose from, gallery transmits the URI of the image or video selected by the user to composer. Then composer uses the uploaded UIR to add attachments. The logic for audio interaction with music applications is similar. The process for shooting images and videos is slightly different from that for recording audio. You can specify the output path in the request intent to specify the output URI through intent. extra_output. Camera will write the data in the specified URI during the shooting process, and then composer will directly read the file from this URI (this is different from 2.3, 2.3 indicates that camera places the file URI in the intent ). Tempfileprovider is used to manage the temporary storage of data when shooting images and videos. The URI passed to camera is "content: // mms_temp_file/scrapspace". This URI is managed by tempfileprovider and used by camera. When camera wants to write data, openfile () is used, tempfileprovider creates a temporary file on the external storage card/sdcard/Android/data/COM. android. MMS/mms_temp_file/scrapspace/.temp.jpg. The images and videos taken by camera are stored in this file. In tempfileprovider, there are also images to operate this file. For example, tempfileprovider.renacescrapfile().pdf rename .temp.jpg to A. 3GP video. In addition to the tempfileprovider used by composer, this temporary file is also used when you edit a slide in slideeditemeditivity, because videos that can be added to images through camera can also be added during slide editing.

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.