Android唯一标识

GitHub地址
Android中能作为唯一标识有四个,但付出一定的代价还是还是能改变,所以目前Android中没有绝对的唯一标识。

1、设备Id(IMEI) (需要授予权限)
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return telephonyManager != null ? telephonyManager.getDeviceId() : null;


2、SIM卡有一个ID(用户可能会换手机卡) (IMSI
SIM卡唯一标识:IMSI 国际移动用户识别码(IMSI:International Mobile Subscriber Identification Number)是区别移动用户的标志,储存在SIM卡中,可用于区别移动用户的有效信息。IMSI由MCC、MNC、MSIN组成
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return telephonyManager != null ? telephonyManager.getSubscriberId() : null;

从上面可以发现,无论是获取IMEI还是IMSI,都使用TelephonyManager这个类,通过getSystemService(Context.TELEPHONY_SERVICE)方法获取 TelephonyManager实列
getDeviceId获取IMEI,getSubscriberId获取IMSI
  

3、Wifi或蓝牙的MAC地址(缺陷:需要权限、且打开蓝牙和WIFI,6.0开始获取不到真实的值
并且Android6.0开始,为了给用户更多的数据保护,Android 移除了通过 WiFi 和蓝牙 API 来在应用程序中可编程的访问本地硬件标示符。现在 WifiInfo.getMacAddress() 和 BluetoothAdapter.getAddress() 方法都将返回 02:00:00:00:00:00

你可能感兴趣的:(Android)