Android------phone manager telephonymanager

Source: Internet
Author: User

Get Telephonymanager:



Telephoneymanager Tmanager = (telephonymanager) getsystem.service (Contex.telephony_service);


Get network and SIM card information:


public class Mainactivity extends Activity {ListView ShowView; String statusnames[]; arraylist<string> statusvalues = new arraylist<string> (), @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main);// Gets the Telephonymanager object of the system Telephonymanager Tmanager = (telephonymanager) getsystemservice (Context.telephony_service) ;//Gets an array of various state names Statusnames = Getresources (). Getstringarray (r.array.statusnames);//Gets an array representing the status of the SIM card string[] Simstate = Getresources (). Getstringarray (r.array.simstate);//Get an array representing the type of telephone network string[] Phonetype = Getresources (). Getstringarray (r.array.phonetype);//Get the device number Statusvalues.add (Tmanager.getdeviceid ());//Get the version of the system platform Statusvalues.add ( Tmanager.getdevicesoftwareversion ()! = null? Tmanager.getdevicesoftwareversion (): "Unknown");//Get Network Operator Code Statusvalues.add (Tmanager.getnetworkoperator ());// Get the network operator name Statusvalues.add (Tmanager.getnetworkoperatorname ());//Get the phone network type Statusvalues.add (phonetype[ Tmanager.getphonEType ()]);//Gets the location of the device Statusvalues.add (tmanager.getcelllocation ()! = null? tmanager.getcelllocation (). toString (): " Statusvalues.add (Tmanager.getsimcountryiso ());//Obtain the SIM card serial number Statusvalues.add ( Tmanager.getsimserialnumber ());//Get SIM card status Statusvalues.add (Simstate[tmanager.getsimstate ());// Get the ListView Object ShowView = (ListView) Findviewbyid (R.id.show); arraylist<map<string, string>> status = new arraylist<map<string, string>> ();// Iterates through the Statusvalues collection, encapsulates statusnames, statusvalues//data into List<map<string, string>> collection for (int i = 0; i < Statusvalues.size (); i++) {hashmap<string, string> map = new hashmap<string, string> (); Map.put ("name", Statusnames[i]); Map.put ( "Value", Statusvalues.get (i)); Status.add (map);} Use Simpleadapter to encapsulate list data Simpleadapter adapter = new Simpleadapter (this, status, R.layout.line,new string[] {"Name", "V Alue "}, new int[] {r.id.name,r.id.value});//Set Adaptershowview.setadapter for ListView (Adapter);}}



   <!--add permission to access your phone's location--    <uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION"/>    <!--add permission to access phone status--    <uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>




Android------phone manager telephonymanager

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.