Android in Getsystemservice detailed

Source: Internet
Author: User

http://blog.sina.com.cn/s/blog_71d1e4fc0100o8qr.htmlhttp://blog.csdn.net/bianhaohui/article/details/6220135 Android background running in a lot of service, they are systemserver on when the system starts, support the normal operation of the system, such as Mountservice Monitoring for SD card installation and removal, Clipboardservice provides the Clipboard function,     Packagemanagerservice provides installation removal and viewing of packages, and so on, applications can access the data provided by the service through the manager interface provided by the system. Getsystemservice is an important API for Android, a method of activity that obtains the corresponding object based on the name passed in, and then translates it into the appropriate service object.            The following describes the system's corresponding services.           Name passed in |         Returned Object | Description
  • Window_service WindowManager managing open Windows programs
  • Layout_inflater_service Layoutinflater Gets the view defined in the XML
  • Activity_service Activitymanager managing the System state of an application
  • Power_service Powermanger power Supply Services
  • Alarm_service Alarmmanager Alarm Clock Service
  • Notification_service Services for Notificationmanager status bar
  • Keyguard_service Keyguardmanager Keypad Lock Service
  • Location_service Locationmanager Location Services, such as GPS
  • Search_service Searchmanager Search for services
  • Vebrator_service vebrator mobile phone Shake service
  • Connectivity_service CONNECTIVITY Network-connected services
  • Wifi_service Wifimanager Wi-Fi service
  • Telephony_service Teleponymanager Telephone Service
Currently available names is:
  • Window_service ("window")
    The top-level window manager in which-can place custom windows. The returned object is a WindowManager.
  • Layout_inflater_service ("Layout_inflater")
    A Layoutinflater for inflating the layout resources in Thiscontext.
  • Activity_service ("Activity")
    A Activitymanager for interacting with the global activity state ofthe system.
  • Power_service ("Power")
    A PowerManager for controlling powermanagement.
  • Alarm_service ("ALARM")
    A Alarmmanager for receiving intents at the time of yourchoosing.
  • Notification_service ("NOTIFICATION")
    A Notificationmanager for informing the user of backgroundevents.
  • Keyguard_service ("Keyguard")
    A Keyguardmanager for controlling Keyguard.
  • Location_service ("Location")
    A Locationmanager for controlling location (e.g., GPS) updates.
  • Search_service ("Search")
    A Searchmanager for handling search.
  • Vibrator_service ("Vibrator")
    A vibrator for interacting with the vibratorhardware.
  • Connectivity_service ("Connection")
    A Connectivitymanager for handling management of networkconnections.
  • Wifi_service ("WiFi")
    A Wifimanager for management of Wi-ficonnectivity.
  • Input_method_service ("Input_method")
    An inputmethodmanager for management of Inputmethods.
  • Ui_mode_service ("Uimode")
    An uimodemanager for controlling UI modes.
  • Download_service ("DOWNLOAD")
    A Downloadmanager for requesting HTTP downloads
Note:system Services obtained via this API is closelyassociated with the Context in which they is obtained from. Ingeneral, do not share the service objects between various differentcontexts (activities, applications, Services, provide Rs,etc.)An example:

Use this piece of code when you get Mobile information from Android:

public class Basicinfo {


Public Stringgetphonenumber ()

{

      //Get phone number MSISDN, most likely empty

      TelephonyManager TM = ( Telephonymanager) (Context.telephony_service);

stringbufferinf = new StringBuffer ();

switch (tm.getsimstate ()) {//getsimstate () Gets the status of the SIM in the following 6 states

                casetelephonymanager.sim_state_absent:inf.append ("no card"); Returninf.tostring ();   

               casetelephonymanager.sim_state_unknown:inf.append ("Unknown state"); returninf.tostring ();  

                 casetelephonymanager.sim_state_network_locked:inf.append ("Requires Networkpin to unlock"), return inf.tostring (); 

           < Span style= "font-family:arial; line-height:26px; " >  casetelephonymanager.sim_state_pin_required:inf.append ("Requires PIN to unlock"); return inf.tostring ();  

           < Span style= "font-family:arial; line-height:26px; " >  casetelephonymanager.sim_state_puk_required:inf.append ("Requires PUK to unlock"); return inf.tostring ();  

caseTelephonyManager.SIM_STATE_READY:break;

}

String PhoneNumber =tm.getline1number ();

Returnphonenumber;

}


When called in another activity class, there is always a process shutdown to get the phone information. later found


getSystemService这个方法基于context,只有存在TextView控件的窗体中这个方法才会被激活~

So:

1. add a constructor with the parameter context to Basicinfo:

Public Basicinfo (Context context)

{

This.context =context;

}

2. Change the Getphonenumber () function to:

Context.getsystemservice (Context.telephony_servic);

3. inside the Calling class Basicinfo bi = Newbasicinfo (this);

Bi.getphonenumber ();

Android in Getsystemservice detailed

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.