Android获取唯一设备号

来源:互联网 发布:sql check约束表达式 编辑:程序博客网 时间:2024/06/16 05:24

TelephoneManager mgr = getSystemService(Context.TELEPHONY_SERVICE);
(权限:<uses-permission android:name="android.permission.READ_PHONE_STATE"/>)
IMSI:国际移动用户识别码 ,获取方法有两种:
imsi=mgr .getSubscriberId();   
imsi=android.os.SystemProperties.get(
              android.telephony.TelephonyProperties.PROPERTY_IMSI);


IMEI:国际移动设备标志,获取方法有两种:
imei = mTelephonyMgr.getDeviceId();
String IMEI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMEI);


android_id:第一次启动时生成,64位十六进制数,恢复出厂设置或者刷机会改变该值,获取方法:
String androidId = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);


mac地址:获取方法(权限<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>)
WifiManager wm = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();




单独获取都不能准确代表设备唯一号,可用三个生成一个uuid
public static String getDeviceUniqueID(Context context) {
String android_id = Secure.getString(context.getContentResolver(),
Secure.ANDROID_ID);
if (TextUtils.isEmpty(android_id))
android_id = "android_id";


WifiManager wm = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
String wifiMacAddress = wm.getConnectionInfo().getMacAddress();
if (TextUtils.isEmpty(wifiMacAddress))
wifiMacAddress = "wifiMacAddress";


TelephonyManager TelephonyMgr = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String imei = TelephonyMgr.getDeviceId();
if (TextUtils.isEmpty(imei))
imei = "imei";


UUID deviceUuid = new UUID(android_id.hashCode(),
((long) imei.hashCode() << 32) | wifiMacAddress.hashCode());
return deviceUuid.toString();
}

0 0
原创粉丝点击