Android 获取设备ID
程序员文章站
2022-04-11 15:41:21
...
权限
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
安卓6.0需动态获取权限:https://blog.csdn.net/meixi_android/article/details/82114026
获取设备ID
String model = "";
TelephonyManager tm = (TelephonyManager) getSystemService(Activity.TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
model = tm.getDeviceId();
Log.i("lgq","ssssssssssss===== "+model);
结果是:
11-05 16:38:46.860 17570-17570/com.tianxin.jifei I/lgq: ssssssssssss===== 862266036040933
获取联网方式:
String access = ""; ConnectivityManager connectionManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo netWorkInfo = connectionManager.getActiveNetworkInfo(); access = netWorkInfo.getTypeName(); Log.i("lgq","ssssssssssss===== "+access);
结果是:
11-05 16:52:49.300 18844-18844/com.tianxin.jifei I/lgq: ssssssssssss===== WIFI
11-05 16:53:02.106 19425-19425/com.tianxin.jifei I/lgq: ssssssssssss===== MOBILE
获取操作系统版本:
/获取操作系统版本
String osVersion = "";
osVersion = android.os.Build.VERSION.RELEASE;
获取运营商:
String providersName = ""; TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } String IMSI = telephonyManager.getSubscriberId(); if (IMSI != null) { if (IMSI.startsWith("46000") || IMSI.startsWith("46002") || IMSI.startsWith("46007")) { providersName = "中国移动"; } else if (IMSI.startsWith("46001") || IMSI.startsWith("46006")) { providersName = "中国联通"; } else if (IMSI.startsWith("46003")) { providersName = "中国电信"; } else { providersName = "其他"; } } else { providersName = "无法获取运营商信息"; }
上一篇: 谷歌正打造超速AI,能像人类一样快速学习
下一篇: python中*号的意义