SIM卡信息和网络信息


SIM卡信息和网络信息   SIM卡信息和网络信息

 

public class Main extends Activity {
	TelephonyManager tm; // 声明TelephonyManager对象的引用
	String[] phoneType = null; // 声明表示手机制式的数组
	String[] simState = null; // 声明表示SIM卡状态的数组
	String[] listItems = null; // 声明列表项的数组
	ArrayList<String> listValues = new ArrayList<String>();

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
		listItems = getResources().getStringArray(R.array.listItem);
		simState = getResources().getStringArray(R.array.simState);
		phoneType = getResources().getStringArray(R.array.phoneType);
		initListValues(); // 初始化列表项的值
		((ListView) findViewById(R.id.lv)).setAdapter(ba);
	}

	public void initListValues() { // 方法:获取各个数据项的值
		listValues.add(tm.getDeviceId()); // 获取设备编号
		listValues.add(tm.getSimCountryIso()); // 获取SIM卡国别
		listValues.add(tm.getSimSerialNumber()); // 获取SIM卡序列号
		listValues.add(simState[tm.getSimState()]); // 获取SIM卡状态
		listValues.add((tm.getDeviceSoftwareVersion() == null ? tm
				.getDeviceSoftwareVersion() : "未知")); // 获取软件版本
		listValues.add(tm.getNetworkOperator()); // 获取网络运营商代号
		listValues.add(tm.getNetworkOperatorName()); // 获取网络运营商名称
		listValues.add(phoneType[tm.getPhoneType()]); // 获取手机 制式
		listValues.add(tm.getCellLocation().toString());// 获取设备当前位置
	}

	BaseAdapter ba = new BaseAdapter() {
		public View getView(int position, View convertView, ViewGroup parent) {
			LinearLayout ll = new LinearLayout(Main.this);
			ll.setOrientation(LinearLayout.VERTICAL); // 设置现象布局的分布方式
			TextView tvItem = new TextView(Main.this);
			TextView tvValue = new TextView(Main.this);
			tvItem.setTextSize(24); // 设置字体大小
			tvItem.setText(listItems[position]); // 设置显示的内容
			tvItem.setGravity(Gravity.LEFT); // 设置在父容器中的对齐方式
			ll.addView(tvItem);
			tvValue.setTextSize(18); // 设置字体大小
			tvValue.setText(listValues.get(position)); // 设置显示的内容
			tvValue.setPadding(0, 0, 10, 10); // 设置四周边界
			tvValue.setGravity(Gravity.RIGHT); // 设置在父容器中的对齐方式
			ll.addView(tvValue); // 将TextView添加到线性布局中
			return ll;
		}

		public long getItemId(int position) { // 重写getItemId方法
			return 0;
		}

		public Object getItem(int position) { // 重写getItem方法
			return null;
		}

		public int getCount() { // 重写getCount方法
			return listItems.length;
		}
	};
}

 

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="listItem"> <!-- 声明一个名为listItem的字符串数组 -->
        <item>设备编号</item>
        <item>SIM卡国别</item>
        <item>SIM卡序列号</item>
        <item>SIM卡状态</item>
        <item>软件版本</item>
        <item>网络运营商代号</item>
        <item>网络运营商名称</item>
        <item>手机制式</item>
        <item>设备当前位置</item>
    </string-array>
    <string-array name="simState"> <!-- 声明一个名为simState的字符串数组 -->
        <item>状态未知</item>
        <item>无SIM卡</item>
        <item>被PIN加锁</item>
        <item>被PUK加锁</item>
        <item>被NetWork PIN加锁</item>
        <item>已准备好</item>
    </string-array>
    <string-array name="phoneType"> <!-- 声明一个名为phoneType的字符串数组 -->
        <item>未知</item>
        <item>GSM</item>
        <item>CDMA</item>
    </string-array>

</resources>

 
 
 

你可能感兴趣的:(网络)