An example of Telephonymanager usage in Android _android

Source: Internet
Author: User

This example describes the Telephonymanager usage in Android. Share to everyone for your reference, specific as follows:

First, overview:

The Telephonymanager class mainly provides a series of get methods for accessing state and information related to mobile communications. This includes the status and information of Mobile SIM, the status of telecom network and the information of mobile phone users. You can use these get methods in your application to obtain related data.

The object of the Telephonymanager class can be obtained by the Context.getsystemservice (Context.telephony_service) method, and it should be noted that some communication information is restricted to the permission of the application. , you need to add the appropriate permissions to it when you develop it.

Second, the example:

@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    Setcontentview (R.layout.activity_main);
    Read the SIM card Telephonymanager TM = (Telephonymanager) this. Getsystemservice (Context.telephony_service); String Tel = tm.getline1number (); Remove MSISDN, most likely an empty//String Iccid = Tm.getsimserialnumber (); Remove Iccid//String IMSI = Tm.getsubscriberid ();
    Remove Imsi System.out.println (Tm.getcallstate ());
    System.out.println (Tm.getdataactivity ());
    System.out.println (Tm.getdatastate ());
    System.out.println ("Get Id,imei or Meid of the device:" + Tm.getdeviceid ());
    SYSTEM.OUT.PRINTLN ("Software version:" +tm.getdevicesoftwareversion ());
    if (Tm.getline1number ()!=null) {System.out.println ("Phone Number:" +tm.getline1number ());
    else {System.out.println ("Phone number is blank"); SYSTEM.OUT.PRINTLN ("Telecommunications network Country:" + tm.getnetworkcountryiso ());
    Telecommunications network Country SYSTEM.OUT.PRINTLN ("telecommunications company Code:" + Tm.getnetworkoperator ()); System.out.println ("Telecommunications company Name:" + tm.getnetworkoperatorname ());
    System.out.println (Tm.getnetworktype ()); Action Network type string[] Networktypearray = {"UNKNOWN", "GPRS", "EDGE", "UMTS", "CDMA", "EVDO 0", "EVDO A", "1xRTT"
    , "HSDPA", "HSUPA", "HSPA"};
    String Networktype = Networktypearray[tm.getnetworktype ()];
SYSTEM.OUT.PRINTLN ("Action Network type:" +networktype);
    System.out.println (Tm.getphonetype ());
    Action communication type string[] Phonetypearray = {"NONE", "GSM", "CDMA"};
    String Phonetype = Phonetypearray[tm.getphonetype ()];
    SYSTEM.OUT.PRINTLN ("Action Communication type:" +phonetype);
    System.out.println ("Sim Country Code:" +tm.getsimcountryiso ());
    System.out.println (Tm.getsimoperator ());
    System.out.println (Tm.getsimoperatorname ());
    System.out.println (Tm.getsimserialnumber ());
    System.out.println (Tm.getsimstate ()); System.out.println (Tm.getsubscriberid ());
Mobile phone IMSI System.out.println (Tm.getvoicemailalphatag ()); System.out.println ("Get location information, mainly the current location of the registered Community Code:" +tm.getcelllocation ());
    System.out.println (Tm.getneighboringcellinfo ()); Mobile roaming status String roamingstatus = Tm.isnetworkroaming ()?
    "Roaming": "Non-roaming";
System.out.println (Roamingstatus); @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds the items to the action Bar if
    It is present.
    Getmenuinflater (). Inflate (R.menu.main, menu);
return true;

 }

For more information on Android-related content readers can view the site topics: "Android Debugging techniques and common problems solution summary", "Android Development introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", " Android Basic Components Usage Summary, Android View tips Summary, Android layout layout tips and Android Control usage summary

I hope this article will help you with the Android program.

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.