This article analyzes the use of Telephonymanager classes in Android using case studies. Share to everyone for your reference. Specifically as follows:
Directory structure:
Main.xml Layout file:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:orientation=" vertical "
android:layout_width=" fill_parent "
android:layout_" height= "Fill_parent" >
<scrollview android:fillviewport= "true"
android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<listview android:id= "@+id/listview"
android:layout_ Width= "Fill_parent"
android:layout_height= "fill_parent"/>
</ScrollView>
</ Linearlayout>
Array.xml file:
<?xml version= "1.0" encoding= "Utf-8"?> <resources> <string-array name= " ListItem "> <item> equipment Number </item> <item>sim Card country </item> <item>sim card serial number </item > <item>sim card status </item> <item> software version </item> <item> network operator Code </item> <it
Em> network operator name </item> <item> mobile phone system </item> <item> device current position </item> </string-array> <string-array name= "Simstate" > <item> status Unknown </item> <item> no SIM card </item> <i Tem> by pin lock </item> <item> PUK lock </item> <item> Network pin lock </item> <item>
; Ready </item> </string-array> <string-array name= "Phonetype" > <item> unknown </item> <item>GSM</item> <item>CDMA</item> </string-array> </resources>
Manifest file:
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
package=" com.ljq.activity "android:versioncode=" 1 "
android:versionname=" 1.0 ">
< Application android:icon= "@drawable/icon"
android:label= "@string/app_name" >
<activity android:name =". Telephonymanageractivity "
android:label=" @string/app_name ">
<intent-filter>
<action Android:name= "Android.intent.action.MAIN"/>
<category
android:name= " Android.intent.category.LAUNCHER "/>
</intent-filter>
</activity>
</ application>
<uses-sdk android:minsdkversion= "7"/>
<uses-permission android:name= " Android.permission.ACCESS_COARSE_LOCATION "/>
<uses-permission android:name=" android.permission.READ_ Phone_state "/>
</manifest>
Telephonymanageractivity class:
Package com.ljq.activity;
Import java.util.ArrayList;
Import android.app.Activity;
Import Android.content.Context;
Import Android.os.Bundle;
Import Android.telephony.TelephonyManager;
Import android.view.Gravity;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.BaseAdapter;
Import Android.widget.LinearLayout;
Import Android.widget.ListView;
Import Android.widget.TextView;
public class Telephonymanageractivity extends activity {private ListView listview=null;
Private Telephonymanager Tm=null;
Private string[] phonetype=null;
Private string[] simstate=null;
Private string[] listitems=null;
Arraylist<string> listvalues=new arraylist<string> ();
Baseadapter adapter=new Baseadapter () {public int getcount () {return listitems.length;
Public Object getitem (int position) {return listitems[position];
public long getitemid (int position) {return position; Public View getview (int position, View Convertview, ViewGroup parent) {linearlayout ll=new linearlayout (telephonymanageractivity.this);
Ll.setorientation (linearlayout.vertical);
TextView tvitem=new TextView (telephonymanageractivity.this);
Tvitem.settextsize (24);
Tvitem.settext (Listitems[position]);
Tvitem.setgravity (gravity.left);//Set Alignment Ll.addview (Tvitem) in the parent container;
TextView tvvalue=new TextView (telephonymanageractivity.this); Tvvalue.settextsize (18); Sets the font size tvvalue.settext (listvalues.get (position)); Set the content displayed tvvalue.setpadding (0, 0, 10, 10);
Setting the perimeter boundary tvvalue.setgravity (gravity.right);
Ll.addview (Tvvalue);
return ll;
}
};
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Listitems=getresources (). Getstringarray (R.array.listitem);
Simstate=getresources (). Getstringarray (R.array.simstate); Phonetype=getresources ().Getstringarray (R.array.phonetype);
Tm= (Telephonymanager) Getsystemservice (Context.telephony_service);
listview= (ListView) Findviewbyid (R.id.listview);
Initlistvalues ();
Listview.setadapter (adapter); /** * Get the value of each data item/public void Initlistvalues () {Listvalues.add (Tm.getdeviceid ());//Get device number Listv Alues.add (Tm.getsimcountryiso ())//Get SIM card country Listvalues.add (Tm.getsimserialnumber ());//Get SIM card serial number Listvalues.add (s Imstate[tm.getsimstate ()]//Get the SIM card status Listvalues.add (Tm.getdevicesoftwareversion ()!=null? Tm.getdevicesoftwareversion (): "Unknown"); Get software version Listvalues.add (Tm.getnetworkoperator ());//Get Network Carrier Code Listvalues.add (Tm.getnetworkoperatorname ()); Get network operator name Listvalues.add (Phonetype[tm.getphonetype ());//Get Mobile phone format listvalues.add (tm.getcelllocation (). toString ())
;//Get Device Current location}}
Run Result:
I hope this article will help you with your Android program.