Reading of SMS Center number

Source: Internet
Author: User
Message Center number concept

SMS Center number is similar to Information Server, if the information center number is not correct, short message can not be sent successfully, each region has its own information center number, which moved to the beginning of +86138, the number of the acquisition of this example. Get method 1, call the Getsmscaddress message method in Phone, where the argument messages are sent to Mhandler when the result is fetched. and query the result property of the results asyncresult.

    		 Phone=phonefactory.getdefaultphone ();
    		 Phone.getsmscaddress (Mhandler.obtainmessage (Event_query_smsc_done)); 

: 2, Mhandler implementation code

Private Handler Mhandler = new Handler () {public
        void Handlemessage (msg) {
            asyncresult ar;
            Switch (msg.what) {case
                Event_query_smsc_done:
                    ar= (asyncresult) msg.obj;
                    if (ar.exception!= null) {
                    } else {
		//Todo:handle exception
		msmsservicecenterpref.setsummary ((String) Ar.result);
		          }
               
                Default: Break;}}
    ;
Principle Analysis

Analysis to this you may feel that the message center number is very simple to obtain, but if you want to implement this feature only add these lines of code, you can try, you will find that the feature is not only not implemented, and even throw a "phonefactory.getdefaultphone must be Called from Looper thread "such an exception.
: 1, cause the root cause of this anomaly in the Phonefactory class of the Getdefaultphone () method to return a phone object, we can enter the class to see the implementation of this function

   public static Phone Getdefaultphone () {
      if (Slooper!= looper.mylooper ()) {
           throw new RuntimeException (
               "Phonefactory.getdefaultphone must be called From Looper thread ");
       }
    
       if (!smadedefaults) {
           throw new illegalstateexception ("Default phones haven ' t been made");
      Return sproxyphone[getdefaultsubscription ()];
   }

This exception is due to the Looper object, Looper.mylooper () is the Looper object of the process where the Getdefaultphone method is invoked, and the Slooper object refers to whose Looper object is assigned. Sproxyphone[getdefaultsubscription () is returned when the Getdefaultphone is invoked, and the array is assigned to that value.

First, the phone process starts when the handset starts, and phone calls to the Phoneapp.java OnCreate method, in which the Phonefactory.makedefaultphones method is invoked. Then, in the Makedefaultphones function, two things are done, one is to initialize the Slooper, and the other is to assign a value to the phone sproxyphone[] array. The following is the core implementation of the method:

 if (!smadedefaults) {slooper = Looper.mylooper ();

                Scontext = context; if (Slooper = = null) {throw new RuntimeException ("phonefactory.makedefaultph
                One must is called from Looper thread ");
       } Sproxyphone = new Phoneproxy[numphones];
                    for (int i = 0; i < numphones i++) {int phonetype = Getphonetype (networkmode[i));

                    LOG.I (Log_tag, "Get Phone Type:" + phonetype);
                                if (Phonetype = = phone.phone_type_gsm) {Sproxyphone[i] = new PhoneProxy (new Gsmphone (context,
                        Scommandsinterface[i], Sphonenotifier, false, DCT, i);
                    LOG.I (Log_tag, "Creating Gsmphone"); else if (Phonetype = = PHONE.PHONE_TYPE_CDMA) {Sproxyphone[i] = new PhoneProxy (New Cdmaphone (con Text, SCommandsinterface[i], Sphonenotifier, false, DCT, i);
                    LOG.I (Log_tag, "Creating Cdmaphone");
 }
                }

Finally, we can see from the front that the Slooper object belongs to the phone process, and Looper.mylooper () is the process that calls the Getdefaultphone function. If the process that calls the Getdefaultphone function and the phone process do not execute in a process space, their Looper object is certainly not the same, then the "Phonefactory.getdefaultphone must be" is definitely thrown Called from Looper thread "this exception.

: 2, the solution first in the need to call the Getdefaultphone function to get the phone object of the process manifest to declare the code

<manifest xmlns:android= "http://schemas.android.com/apk/res/android"
        package= "Com.android.mms"
        Android:shareduserid= "Android.uid.phone" >

And the specific activity is declared with the following attributes:

Android:process= "Com.android.phone"
Summarize

The text message center number reads, here only narrated the application layer most basic realization as well as some attention matters, its most core realization still implemented to the middle layer and the RIL level. Reference class Ril.java, Phonebase.java.

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.