权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Java代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
try {
// 获取设备编号
String num = manager.getDeviceId();
// 获取系统平台版本
String version = manager.getDeviceSoftwareVersion() != null ? manager.getDeviceSoftwareVersion() : "未知";
// 获取网络运营商代号
String yysNum = manager.getNetworkOperator();
// 获取网络运营商名称
String yysName = manager.getNetworkOperatorName();
// 获取手机网络类型
int networkType = manager.getPhoneType();
// 获取设备所在位置
String location = manager.getCellLocation() != null ? manager.getCellLocation().toString() : "未知位置";
// 获取SIM卡的国别
String countryType = manager.getSimCountryIso();
// 获取SIM卡的序列号
String xlh = manager.getSimSerialNumber();
// 获取SIM卡的状态
int simMode = manager.getSimState();
Log.i("info", "设备编号" + num);
Log.i("info", "系统平台版本" + version);
Log.i("info", "网络运营商代号" + yysNum);
Log.i("info", "网络运营商名称" + yysName);
Log.i("info", "手机网络类型" + networkType);
Log.i("info", "设备所在位置" + location);
Log.i("info", "SIM卡的国别" + countryType);
Log.i("info", "SIM卡的序列号" + xlh);
Log.i("info", "SIM卡的状态" + simMode);
} catch (Exception e) {
e.printStackTrace();
}
输出内容: