2016年3月3日 星期四

Android Unique Identifiers

1. Android ID

androidId = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);

http://developer.android.com/intl/zh-tw/reference/android/provider/Settings.Secure.html#ANDROID_ID
  • A 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device. The value may change if a factory reset is performed on the device.
  • Each android profile(on same device) has its own android id
    http://stackoverflow.com/questions/13408349/implications-of-android-multiple-user-support-new-in-4-2-for-server-side-data/13465373#13465373
  • Some devices before Android 2.2 have same android id : 9774d56d682e549c

2. UUID

uuid = UUID.randomUUID().toString();
http://developer.android.com/intl/zh-tw/reference/java/util/UUID.html

  • UUID is an immutable representation of a 128-bit universally unique identifier (UUID).
  • Generated by JAVA, each APP has their own UUID
  • UUID may change if execute "clean data" or uninstall APP

3. Device ID(UDID) (IMEI/MEID)

TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);deviceId = tm.getDeviceId();

  • WIFI Version(no GSM) device has no IMEI
  • Need READ_PHONE_STATE privilege
  • Unique on each device

4. Advertise ID 

https://support.google.com/googleplay/android-developer/answer/6048248?hl=zh-Hant
public String getAdvertisingId () {
    if(mAdvertisingId != null) return mAdvertisingId;    AsyncTask, 
Void, String> task = new AsyncTask, Void, String>() {
@Override protected String doInBackground(Void... params) {
AdvertisingIdClient.Info idInfo = null; try {
idInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext.getApplicationContext()); Log.v(TAG, "get idInfo : " + idInfo.toString()); } catch (GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException | IOException e) {
e.printStackTrace(); }
String advertId = null; try{
advertId = idInfo.getId(); mAdvertisingId = advertId; Log.v(TAG, "do In background : " + mAdvertisingId); }catch (NullPointerException e){
e.printStackTrace(); }
return advertId; }
}; task.execute(); return mAdvertisingId;}
 
  • User can reset advertising id manually
  • Need Google Play Services SDK
  • https://www.safaribooksonline.com/blog/2014/01/16/advertising-id-android-kitkat/

5. Serial ID

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
    serialId = Build.SERIAL;} 
  • Unique on each device
  • Need API Level >= 2.3


6. Subscribe ID (like UDID)

TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);subscriberId = tm.getSubscriberId();

  • Need READ_PHONE_STATE privilege
  • Unique on each device




Ref : http://blog.mosil.biz/2014/05/android-device-id-uuid/


沒有留言:

張貼留言