Is there a unique Android device ID?
来源:互联网 发布:嵌入式linux编程 pdf 编辑:程序博客网 时间:2024/06/05 10:06
Settings.Secure#ANDROID_ID
returns the Android ID as an unique 64-bit hex string.
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
There are many answers to this question, most of which will only work "some" of the time, and unfortunately that's not good enough.
Based on my tests of devices (all phones, at least one of which is not activated):
- All devices tested returned a value for
TelephonyManager.getDeviceId()
- All GSM devices (all tested with a SIM) returned a value for
TelephonyManager.getSimSerialNumber()
- All CDMA devices returned null for
getSimSerialNumber()
(as expected) - All devices with a Google account added returned a value for
ANDROID_ID
- All CDMA devices returned the same value (or derivation of the same value) for both
ANDROID_ID
and TelephonyManager.getDeviceId()
-- as long as a Google account has been added during setup. - I did not yet have a chance to test GSM devices with no SIM, a GSM device with no Google account added, or any of the devices in airplane mode.
So if you want something unique to the device itself, TM.getDeviceId() should be sufficient. Obviously some users are more paranoid than others, so it might be useful to hash 1 or more of these identifiers, so that the string is still virtually unique to the device, but does not explicitly identify the user's actual device. For example, using String.hashCode(), combined with a UUID:
final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, tmPhone, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String deviceId = deviceUuid.toString();
might result in something like: 00000000-54b3-e7c7-0000-000046bffd97
It works well enough for me.
Also you might consider the WiFi adapter's MAC address. Retrieved thusly:
WifiManager wm = (WifiManager)Ctxt.getSystemService(Context.WIFI_SERVICE);
return wm.getConnectionInfo().getMacAddress();
Reported to be available even when WiFi is not connected. If Joe from the answer above gives this one a try on his many devices, that'd be nice.
In some case,you may want do get Uniquely Identifying for a 'real' android phone,and you can do it like this:
In Android.Provider.Settings.System we have some interesting values that could be of use, one specifically is “Android_ID”. From the documentation it is the following;
String ANDROID_ID The Android ID (a unique 64-bit value) as a hex string. “android_id”[code]import Android.Provider.Settings.System;
...
String Android_ID = System.getString(this.getContentResolver(), System.ANDROID_ID); [/code]Also, note that in an emulator this will return “null”, though a real device will return an actual value. The nice thing about this tid-bit of code is that you are not required any special permissions to call it, since it’s essentially a passive call to get information. No write access is (obviously) required.
- Is there a unique Android device ID?
- Is there a unique Android device ID?
- Android Unique Device ID
- How to retrieve the Device Unique ID from android device
- STM32 Unique device ID reading
- stm32 unique device id (UDID)
- STM32F0唯一ID ,Unique device ID ,UID
- there is a reason
- Chanel iPhone 6 Cases the fact is that there exists a unique respected established
- Is there a way to customize Android default tabs
- android There is a problem parsing the package
- LINK - WinRT: get unique device id
- There is already a statement named SysUser.getUserByOrganCode in this SqlMap. spring id相同
- "There is not a valid medialib id!"与解析wav文件格式
- Where there is a will,there is a way...
- Where there is a will, there is a way
- There is a board with
- Android 获取Device Id
- PC挂载jffs2
- 本地phpmyadmin远程连接服务器端MySQL
- Spring的依赖注入(DI)之Setter注入(2)
- java连接mysql
- Thunderbird 3 配置发送gmail办法
- Is there a unique Android device ID?
- rsync命令详解
- Is there a unique Android device ID?
- JSP构成元素-JSP基础
- 基础
- C#读DB(access)
- 幽默笑话
- linear regression
- socket执行流程图