Workaround: turn off Mobile data, receive MMS messages, and not receive download MMS successfully

Source: Internet
Author: User
<span id="Label3"></p>"preconditions" to turn off data services<br>"action steps" to send mms, or receive MMS<br>"test results" cannot send mms; content cannot be downloaded after MMS is received<br><p><p>"expected results" to send and receive MMS messages normally</p></p><p><p>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 business, before the MMS is sent to open the data network to detect, assuming that 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.</p></p><p><p></p></p><p><p>Positioned according to the Code. The business logic sent by MMS is mainly concentrated in the Transactionservice class. We therefore make the following analysis and Changes:</p></p><p><p>Private Boolean isnetworkavailable () {<br>Networkinfo ni = Mconnmgr.getnetworkinfo (connectivitymanager.type_mobile_mms);<br>return (ni = = Null?)</p></p><p><p><strong>false:ni.isAvailable ()) && mconnmgr.getmobiledataenabled ();</strong><br>}<br></p></p><p><p>In the above code we find that this method is used to get the service of the current network connection and to infer whether the current network state is available, because our change target is that the MMS service is no longer limited by the state of the current data service. So we changed to assume that the network connection service is not empty, we can send and receive MMS Business:<br></p></p><p><p>Private Boolean isnetworkavailable () {<br>Networkinfo ni = Mconnmgr.getnetworkinfo (connectivitymanager.type_mobile_mms);<br>return (ni = = null? False: <span style="color: #FF0000"><strong>true</strong></span>;<br>}</p></p><p><p>The following code is a detailed function to start the MMS business, the red part is the part we added, the main logic is to get the state of the current network connection settings, and save the state (state in the Mmsconfig class), and then start the transfer of MMS Service:</p></p><p>protected int beginmmsconnectivity () throws IOException {<br>Take a wake lock so we don ' t fall asleep before the message is Downloaded.<br>Createwakelock ();<br><br>int result = Mconnmgr.startusingnetworkfeature (<br>connectivitymanager.type_mobile, phone.feature_enable_mms);<br><br>If (log.isloggable (logtag.transaction, Log.verbose) | | DEBUG) {<br>LOG.V (TAG, "beginmmsconnectivity:result=" + result);<br>}<br><span style="color: #FF0000"><strong>Boolean bmobiledataenabled = mconnmgr.getmobiledataenabled ();<br>If (!bmobiledataenabled) {<br>Mmsconfig.setdataconnectenabled (false);<br>Mconnmgr.setmobiledataenabled (true);<br>mservicehandler.sendemptymessagedelayed (event_mms_connectivity_timeout, mms_auto_open_connectivity_delay);<br>Acquirewakelock ();<br>Return phone.apn_request_started;//the Phone class is not found here because of the version number Problem. Can try<span class="wdi"><span class="wdi"><span class="typ">phoneconstants</span></span></span>This class<br>}</strong></span><br>Switch (result) {<br>Case Phone.apn_already_active:<br>Acquirewakelock ();<br>Return result;<br>Case Phone.apn_request_started:<br>Acquirewakelock ();<br>mservicehandler.sendemptymessagedelayed (event_mms_connectivity_timeout, mms_connectivity_delay);<br>/* Add 20120823 ts-fmc-v2 start */<br>If (featurequery.feature_ct_fmc_support) {<br>Broadcastfmcconnectivity (wifimanager.fmc_mms_start);<br>}<br>/* Add 20120823 Ts-fmc-v2 End */<br>Return result;<br>}<br><br>throw new IOException ("cannot establish MMS connectivity");<br>}<br></p><p><p>Add a line of code here:</p></p><p><p><span style="color: #FF0000"><strong>private static final int mms_auto_open_connectivity_delay = 1 * 1000;//set delay time is 1 seconds</strong></span><br></p></p><p><p>The following code is the detailed function that ends the MMS business, and the red part is the part we Added. Get us to start the MMS business before saving the state, and restore the state we saved, and end the MMS business (red part of the code we added):</p></p><p>protected void endmmsconnectivity () {<br>try {<br>If (log.isloggable (logtag.transaction, Log.verbose) | | DEBUG) {<br>LOG.V (TAG, "endmmsconnectivity");<br>}<br><span style="color: #FF0000"><span style="color: #FF0000"><strong>If (mprocessing.isempty ()) {<br>If (! mmsconfig.getdataconnectenabled ()) {<br>Mmsconfig.setdataconnectenabled (true);<br>Mconnmgr.setmobiledataenabled (false);<br>}<br>}</strong></span></span><br>Cancel timer for renewal of lease<br>Mservicehandler.removemessages (event_continue_mms_connectivity);<br>If (mconnmgr! = Null) {<br>Mconnmgr.stopusingnetworkfeature (<br>connectivitymanager.type_mobile,<br>phone.feature_enable_mms);<br>/* Add 20120823 ts-fmc-v2 start */<br>If (featurequery.feature_ct_fmc_support) {<br>Broadcastfmcconnectivity (wifimanager.fmc_mms_stop);<br>}<br>/* Add 20120823 Ts-fmc-v2 End */<br>}<br>} finally {<br>Releasewakelock ();<br>}<br>}<br></p><p><p>Here we post the code that holds the current data connection state (to restore the state of the data Connection) in the Mmsconfig class:</p></p><p><p><span style="color: #FF0000"><strong>private static Boolean mdataconnectenabled =true;<br></strong></span></p></p><p><p><span style="color: #FF0000"><strong>public static Boolean getdataconnectenabled () {<br>Return mdataconnectenabled;<br>}<br>public static void setdataconnectenabled (boolean Bdataenable) {<br>mdataconnectenabled = bdataenable;<br>}</strong></span><br></p></p><p><p><br></p></p><p><p>The two classes modified in this article are in the MMS application in the source code, and the two Java source code files that have been modified here have been packaged and uploaded to Csdn. Need to be able to download a friend to See: click to open the link<br></p></p> <p><p>Workaround: turn off Mobile data, receive MMS messages, and not receive download MMS successfully</p></p></span>

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.