Public class huoqu extends listactivity {private telephonymanager telmgr; private list <string> item = new arraylist <string> (); Private list <string> value = new arraylist <string> (); @ suppresswarnings ("static-access") @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate);/* load main. XML Layout */setcontentview (R. layout. main); telmgr = (telephonymanager) getsys Temservice (telephony_service);/* write the obtained information to the list * // * obtain the mobile phone number */item. add (getresources (). gettext (R. string. str_list0 ). tostring (); If (telmgr. getline1number ()! = NULL) {value. add (telmgr. getline1number ();} else {value. add ("unable to get");}/* obtain telecom network country */item. add (getresources (). gettext (R. string. str_list1 ). tostring (); If (telmgr. getnetworkcountryiso (). equals ("") {value. add ("unable to get");} else {value. add ("" + telmgr. getnetworkcountryiso ();}/* Get the telecom company code */item. add (getresources (). gettext (R. string. str_list2 ). tostring (); If (telmgr. getnetworkoperator (). equals (" ") {Value. add ("unable to get");} else {value. add (telmgr. getnetworkoperator ();}/* Get the telecom company name */item. add (getresources (). gettext (R. string. str_list3 ). tostring (); If (telmgr. getnetworkoperatorname (). equals ("") {value. add ("unable to get");} else {value. add (telmgr. getnetworkoperatorname ();}/* get action communication type */item. add (getresources (). gettext (R. string. str_list4 ). tostring (); If (telmgr. getphonetype () = telmgr. phon E_type_gsm) {value. add ("GSM");} else {value. add ("unknown");}/* Get network type */item. add (getresources (). gettext (R. string. str_list5 ). tostring (); If (telmgr. getnetworktype () = telmgr. network_type_edge) {value. add ("edge");} else if (telmgr. getnetworktype () = telmgr. network_type_gprs) {value. add ("GPRS");} else if (telmgr. getnetworktype () = telmgr. network_type_umts) {value. add ("UMTS");} else if (Tel Mgr. getnetworktype () = 4) {value. add ("HSDPA");} else {value. add ("unknown");}/* Get roaming status */item. add (getresources (). gettext (R. string. str_list6 ). tostring (); If (telmgr. isnetworkroaming () {value. add ("Roaming");} else {value. add ("No roaming");}/* Get Mobile Phone IMEI */item. add (getresources (). gettext (R. string. str_list7 ). tostring (); value. add (telmgr. getdeviceid ();/* Get imei sv */item. add (getresources (). gettext (R. st Ring. str_list8). tostring (); If (telmgr. getdevicesoftwareversion ()! = NULL) {value. add (telmgr. getdevicesoftwareversion ();} else {value. add ("unable to get");}/* Get Mobile Phone imsi */item. add (getresources (). gettext (R. string. str_list9 ). tostring (); If (telmgr. getsubscriberid ()! = NULL) {value. add (telmgr. getsubscriberid ();} else {value. add ("cannot be obtained");}/* Get contentresolver */contentresolver CV = huoqu. this. getcontentresolver (); string TMPS = "";/* Get Bluetooth status */item. add (getresources (). gettext (R. string. str_list10 ). tostring (); TMPS = android. provider. settings. system. getstring (CV, android. provider. settings. system. then th_on); If (TMPS. equals ("1") {value. add ("enabled");} else {value. add ("not enabled");}/* get WiFi status */item. add (getresources (). gettext (R. string. str_list11 ). tostring (); TMPS = android. provider. settings. system. getstring (CV, android. provider. settings. system. wifi_on); If (TMPS. equals ("1") {value. add ("enabled");} else {value. add ("not opened");}/* get the flight mode whether to open */item. add (getresources (). gettext (R. string. str_list12 ). tostring (); TMPS = android. provider. settings. system. getstring (CV, android. provider. settings. system. airplane_mode_on); If (TMPS. equals ("1") {value. add ("open");} else {value. add ("not opened");}/* obtain whether data roaming is enabled */item. add (getresources (). gettext (R. string. str_list13 ). tostring (); TMPS = android. provider. settings. system. getstring (CV, android. provider. settings. system. data_roaming); If (TMPS. equals ("1") {value. add ("open");} else {value. add ("not opened");}/* use a custom myadapter to pass data to listactivity */setlistadapter (New myadapter (this, item, value ));}}
/* Custom adapter, inherited from Android. widget. baseadapter */public class myadapter extends baseadapter {/* variable Declaration */private layoutinflater minflater; private list <string> items; private list <string> values;/* myadapter constructor, input three parameters */Public myadapter (context, list <string> item, list <string> value) {/* parameter initialization */minflater = layoutinflater. from (context); items = item; values = value;}/* because the baseadapter is inherited, the following method must be overwritten */@ override public int getcount () {return items. size () ;}@ override public object getitem (INT position) {return items. get (position) ;}@ override public long getitemid (INT position) {return position ;}@ override public view getview (INT position, view convertview, viewgroup par) {viewholder holder; if (convertview = NULL) {/* use the custom file_row as Layout */convertview = minflater. inflate (R. layout. row_layout, null);/* initialize the text and Icon */holder = new viewholder (); holder. text1 = (textview) convertview. findviewbyid (R. id. mytext1); holder. text2 = (textview) convertview. findviewbyid (R. id. mytext2); convertview. settag (holder);} else {holder = (viewholder) convertview. gettag ();}/* set the information to be displayed */holder. text1.settext (items. get (position ). tostring (); holder. text2.settext (values. get (position ). tostring (); Return convertview;}/* class viewholder */private class viewholder {/* text1: Information name * text2: Information Content */textview text1; textview text2 ;}}
<! -- Declare read_phone_state permission --> <uses-Permission Android: Name = "android. Permission. read_phone_state"> </uses-Permission>