获取网络和SIM卡信息
2015-04-06 20:45
211 查看
/TelephonyStatus/src/com/lxm/telephonystatus/MainActivity.java
package com.lxm.telephonystatus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
ListView show ;
ArrayList<String> statusValues = new ArrayList<String>();
String[] statusNames;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
show = (ListView) findViewById(R.id.show);
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
statusNames = getResources().getStringArray(R.array.statusNames);
String[] phoneType = getResources().getStringArray(
R.array.phoneType);
String[] simState = getResources()
.getStringArray(R.array.simState);
statusValues.add(tManager.getDeviceId());
statusValues.add(tManager.getDeviceSoftwareVersion()
!= null ? tManager.getDeviceSoftwareVersion() : "未知");
statusValues.add(tManager.getNetworkOperator());
statusValues.add(tManager.getNetworkOperatorName());
statusValues.add(phoneType[tManager.getPhoneType()]);
statusValues.add(tManager.getCellLocation() != null ? tManager
.getCellLocation().toString() : "未知位置");
statusValues.add(tManager.getSimCountryIso());
statusValues.add(tManager.getSimSerialNumber());
statusValues.add(simState[tManager.getSimState()]);
ArrayList<Map<String, String>> status = new ArrayList<Map<String,String>>();
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);
}
SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, status,
R.layout.line, new String[]{"name","value"}, new int[]{R.id.name,R.id.value});
show.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
/TelephonyStatus/res/layout/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ListView
android:id="@+id/show"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
/TelephonyStatus/res/layout/line.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_heigh
4000
t="wrap_content"
android:width="120px"
android:textSize="16dip"
/>
<TextView
android:id="@+id/value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8px"
android:textSize="16dip"
/>
</LinearLayout>
/TelephonyStatus/res/values/array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 声明一个名为statusNames的字符串数组 -->
<string-array name="statusNames">
<item>设备编号</item>
<item>软件版本</item>
<item>网络运营商代号</item>
<item>网络运营商名称</item>
<item>手机制式</item>
<item>设备当前位置</item>
<item>SIM卡的国别</item>
<item>SIM卡序列号</item>
<item>SIM卡状态</item>
</string-array>
<!-- 声明一个名为simState的字符串数组 -->
<string-array name="simState">
<item>状态未知</item>
<item>无SIM卡</item>
<item>被PIN加锁</item>
<item>被PUK加锁</item>
<item>被NetWork PIN加锁</item>
<item>已准备好</item>
</string-array>
<!-- 声明一个名为phoneType的字符串数组 -->
<string-array name="phoneType">
<item>未知</item>
<item>GSM</item>
<item>CDMA</item>
</string-array>
</resources>
添加权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 添加访问手机状态的权限 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
运行效果图:
源码下载
package com.lxm.telephonystatus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
ListView show ;
ArrayList<String> statusValues = new ArrayList<String>();
String[] statusNames;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
show = (ListView) findViewById(R.id.show);
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
statusNames = getResources().getStringArray(R.array.statusNames);
String[] phoneType = getResources().getStringArray(
R.array.phoneType);
String[] simState = getResources()
.getStringArray(R.array.simState);
statusValues.add(tManager.getDeviceId());
statusValues.add(tManager.getDeviceSoftwareVersion()
!= null ? tManager.getDeviceSoftwareVersion() : "未知");
statusValues.add(tManager.getNetworkOperator());
statusValues.add(tManager.getNetworkOperatorName());
statusValues.add(phoneType[tManager.getPhoneType()]);
statusValues.add(tManager.getCellLocation() != null ? tManager
.getCellLocation().toString() : "未知位置");
statusValues.add(tManager.getSimCountryIso());
statusValues.add(tManager.getSimSerialNumber());
statusValues.add(simState[tManager.getSimState()]);
ArrayList<Map<String, String>> status = new ArrayList<Map<String,String>>();
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);
}
SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, status,
R.layout.line, new String[]{"name","value"}, new int[]{R.id.name,R.id.value});
show.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
/TelephonyStatus/res/layout/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ListView
android:id="@+id/show"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
/TelephonyStatus/res/layout/line.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_heigh
4000
t="wrap_content"
android:width="120px"
android:textSize="16dip"
/>
<TextView
android:id="@+id/value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8px"
android:textSize="16dip"
/>
</LinearLayout>
/TelephonyStatus/res/values/array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 声明一个名为statusNames的字符串数组 -->
<string-array name="statusNames">
<item>设备编号</item>
<item>软件版本</item>
<item>网络运营商代号</item>
<item>网络运营商名称</item>
<item>手机制式</item>
<item>设备当前位置</item>
<item>SIM卡的国别</item>
<item>SIM卡序列号</item>
<item>SIM卡状态</item>
</string-array>
<!-- 声明一个名为simState的字符串数组 -->
<string-array name="simState">
<item>状态未知</item>
<item>无SIM卡</item>
<item>被PIN加锁</item>
<item>被PUK加锁</item>
<item>被NetWork PIN加锁</item>
<item>已准备好</item>
</string-array>
<!-- 声明一个名为phoneType的字符串数组 -->
<string-array name="phoneType">
<item>未知</item>
<item>GSM</item>
<item>CDMA</item>
</string-array>
</resources>
添加权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 添加访问手机状态的权限 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
运行效果图:
源码下载
相关文章推荐
- Android 获取手机网络、SIM卡等信息
- Android 获取手机设备信息、网络信息、SIM卡信息
- 手机信息的获取(手机IMEI,手机sim卡的IMSI,网络类型(WiFi,LTE(即4G)等),信号强度(蜂窝网络非WiFi),经纬度)
- 在vb中使用Iphlpapi.dll获取网络信息 第四章 第三节 实例一:网络数据流量图
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第十六节 获取本机IP 路由表
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第六节 获取当前UDP连接情况
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第七节 获取本机网间控制报文协议(ICMP)信息
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第一节 获取本机网络适配器的信息
- 在vb中使用Iphlpapi.dll获取网络信息 第四章 第一节 错误代码
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第十四节 返回本机网络接口数量
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第十五节 设置本机默认的生存时间(time-to-live:TTL)值
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第二十节 测定到指定目的地往返时间和跳跃数
- [原创]在vb中使用Iphlpapi.dll获取网络信息 目录
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第二十一节 增加和删除一个IP地址
- 在vb中使用Iphlpapi.dll获取网络信息 第三章 第一节 IPHLPAPI 的其它函数
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第十七节 设置TCP连接状态
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第二节 获取MIB-II 接口表
- 在vb中使用Iphlpapi.dll获取网络信息 第一章 前言
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第九节 获取网卡–IP地址映射表
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第十九节 Ping一个IP地址