Home>

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>device 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>
    <item>Network operator name</item>
    <item>Phone System</item>
    <item>Device current position</item>
  </string-array>
  <string-array name="simstate">
    <item>Status unknown</item>
    <item>no sim card</item>
    <item>pin locked</item>
    <item>locked by puk</item>
    <item>locked by network pin</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 the alignment in the parent container
      ll.addview (tvitem);
      textview tvvalue=new textview (telephonymanageractivity.this);
      tvvalue.settextsize (18);//Set the font size
      tvvalue.settext (listvalues.get (position));//Set the displayed content
      tvvalue.setpadding (0, 0, 10, 10);//Set the surrounding boundaries
      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 the device number
    listvalues.add (tm.getsimcountryiso ());//Get sim card country
    listvalues.add (tm.getsimserialnumber ());//Get the sim card serial number
    listvalues.add (simstate [tm.getsimstate ()]);//Get sim card status
    listvalues.add ((tm.getdevicesoftwareversion ()!=null?tm.getdevicesoftwareversion ():"Unknown"));//Get software version
    listvalues.add (tm.getnetworkoperator ());//Get the network operator code
    listvalues.add (tm.getnetworkoperatorname ());//Get the network operator name
    listvalues.add (phonetype [tm.getphonetype ()]);//Get the phone format
    listvalues.add (tm.getcelllocation (). tostring ());//Get the current location of the device
  }
}

operation result:

  • Previous Analysis of the automatic operation method of PHP file
  • Next C # P2P voice chat tool based on UDP