Workaround: Turn off mobile data, receive MMS messages, and not receive download MMS successfully

Source: Internet
Author: User

"Preconditions" to turn off data services
"Action steps" to send MMS, or receive MMS
"Test results" cannot send MMS messages, content cannot be downloaded after MMS is received

Expected results to send and receive MMS messages normally

After analysis we found that because the sending of MMS needs data business open for support, the data business is closed, you can not send MMS, so we do not affect the MMS service, before the MMS is sent to the data network is open to detect, if the data business is set to a closed state, we open the data service to send multimedia messages, When the MMS is sent at the end of the business, we keep the data business in the original state.

Based on code positioning, the business logic sent by MMS is mainly focused on the Transactionservice class, so we make the following analysis and modifications:

Private Boolean isnetworkavailable () {
Networkinfo ni = Mconnmgr.getnetworkinfo (Connectivitymanager.type_mobile_mms);
return (NI = = null?) false:ni.isAvailable ()) && mconnmgr.getmobiledataenabled ();
}

In the above code we find that this method is used to get the current network connection service and to determine whether the current network status is available, because of our modification target, the MMS service is no longer subject to the current state of the data business, so we modified to if the network connection service is not empty, we can send and receive MMS business:

Private Boolean isnetworkavailable () {
Networkinfo ni = Mconnmgr.getnetworkinfo (Connectivitymanager.type_mobile_mms);
return (NI = = null? False: true;
}

The following code is a specific function to start the MMS business, the red part of our added part, the main logic is to get the current network connection settings, and save the State (state in the Mmsconfig Class), and then start the transfer of MMS service:

protected int beginmmsconnectivity () throws IOException {
Take a wake lock so we don ' t fall asleep before the message is downloaded.
Createwakelock ();

int result = Mconnmgr.startusingnetworkfeature (
Connectivitymanager.type_mobile, Phone.feature_enable_mms);

if (log.isloggable (logtag.transaction, log.verbose) | | DEBUG) {
LOG.V (TAG, "beginmmsconnectivity:result=" + result);
}
Boolean bmobiledataenabled = mconnmgr.getmobiledataenabled ();
if (!bmobiledataenabled) {
Mmsconfig.setdataconnectenabled (FALSE);
Mconnmgr.setmobiledataenabled (TRUE);
Mservicehandler.sendemptymessagedelayed (Event_mms_connectivity_timeout, Mms_auto_open_connectivity_delay);
Acquirewakelock ();
Return phone.apn_request_started;//because of the version problem here if you can't find the Phone class, you can tryphoneconstantsThis class
}

Switch (Result) {
Case Phone.apn_already_active:
Acquirewakelock ();
return result;
Case phone.apn_request_started:
Acquirewakelock ();
Mservicehandler.sendemptymessagedelayed (Event_mms_connectivity_timeout, Mms_connectivity_delay);
/* ADD 20120823 ts-fmc-v2 start */
if (Featurequery.feature_ct_fmc_support) {
Broadcastfmcconnectivity (Wifimanager.fmc_mms_start);
}
/* ADD 20120823 ts-fmc-v2 End */
return result;
}

throw new IOException ("Cannot establish MMS connectivity");
}

Add a line of code here:

private static final int mms_auto_open_connectivity_delay = 1 * 1000;//Set delay time is 1 seconds

The following code is a specific function to end the MMS business, the red part of our added part, get us to start MMS business before the state of saving, and restore the state we saved, and end the MMS business (red part of the code we added):

protected void endmmsconnectivity () {
try {
if (log.isloggable (logtag.transaction, log.verbose) | | DEBUG) {
LOG.V (TAG, "endmmsconnectivity");
}
if (Mprocessing.isempty ()) {
if (! Mmsconfig.getdataconnectenabled ()) {
Mmsconfig.setdataconnectenabled (TRUE);
Mconnmgr.setmobiledataenabled (FALSE);
}
}

Cancel timer for renewal of lease
Mservicehandler.removemessages (event_continue_mms_connectivity);
if (mconnmgr! = null) {
Mconnmgr.stopusingnetworkfeature (
Connectivitymanager.type_mobile,
PHONE.FEATURE_ENABLE_MMS);
/* ADD 20120823 ts-fmc-v2 start */
if (Featurequery.feature_ct_fmc_support) {
Broadcastfmcconnectivity (Wifimanager.fmc_mms_stop);
}
/* ADD 20120823 ts-fmc-v2 End */
}
} finally {
Releasewakelock ();
}
}

Here we post the code that holds the current data connection state (to restore the state of the data connection) in the Mmsconfig class:

private static Boolean mdataconnectenabled =true;

public static Boolean getdataconnectenabled () {
return mdataconnectenabled;
}
public static void Setdataconnectenabled (Boolean bdataenable) {
mdataconnectenabled = bdataenable;
}


The two classes modified in this article are located in the source code in the MMS application, where the modified two Java source files have been packaged to upload to CSDN, the need for friends can download to see: Click to open the link

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.