@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 读取sim卡
TelephonyManager tm = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
//
// String tel = tm.getLine1Number(); // 取出MSISDN,很可能为空
// String iccid = tm.getSimSerialNumber(); // 取出ICCID
// String imsi = tm.getSubscriberId(); // 取出IMSI
System.out.println(tm.getCallState());
System.out.println(tm.getDataActivity());
System.out.println(tm.getDataState());
System.out.println("得到设备的ID,IMEI或者MEID:" + tm.getDeviceId());
System.out.println("软件版本:"+tm.getDeviceSoftwareVersion());
if (tm.getLine1Number()!=null) {
System.out.println("电话号码:"+tm.getLine1Number());
} else {
System.out.println("电话号码为空");
}
System.out.println("電信網路國別:" + tm.getNetworkCountryIso()); // 電信網路國別
System.out.println("電信公司代號:" + tm.getNetworkOperator());
System.out.println("電信公司名稱:" + tm.getNetworkOperatorName());
// System.out.println(tm.getNetworkType());
// 行動網路類型
String[] networkTypeArray = { "UNKNOWN", "GPRS", "EDGE", "UMTS",
"CDMA", "EVDO 0", "EVDO A", "1xRTT", "HSDPA", "HSUPA", "HSPA" };
String networkType = networkTypeArray[tm.getNetworkType()];
System.out.println("行動網路類型:"+networkType);
// System.out.println(tm.getPhoneType());
// 行動通訊類型
String[] phoneTypeArray = {"NONE", "GSM", "CDMA"};
String phoneType = phoneTypeArray[tm.getPhoneType()];
System.out.println("行動通訊類型:"+phoneType);
System.out.println("sim国家代码:"+tm.getSimCountryIso());
System.out.println(tm.getSimOperator());
System.out.println(tm.getSimOperatorName());
// System.out.println(tm.getSimSerialNumber());
System.out.println(tm.getSimState());
// System.out.println(tm.getSubscriberId()); // 手機 IMSI
System.out.println(tm.getVoiceMailAlphaTag());
// System.out.println("得到位置信息,主要是当前注册小区的位置码:"+tm.getCellLocation());
// System.out.println(tm.getNeighboringCellInfo());
// 手機漫遊狀態
String roamingStatus = tm.isNetworkRoaming() ? "漫遊中" : "非漫遊";
System.out.println(roamingStatus);
}
@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;
}
Android的TelephonyManager用法
最新推荐文章于 2023-08-09 16:29:41 发布