There are several occasions when the unique identifier of a device is required. For instance you need it to generate a serial key and unlock a trial version, to generate encryption keys or to have the unique signature of a device.
On Android there are several ways to get such an ID.

  • The IMEI

  • Pseudo-Unique ID

  • The Android ID

  • The WLAN MAC Address string

  • The BT MAC Address string

1. The IMEI: only for Android devices with Phone use:

    TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String szImei = TelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE

This requires adding a permission in AndroidManifest.xml, and users will be notified upon installing your software: android.permission.READ_PHONE_STATE. The IMEI is unique for your phone and it looks like this: 359881030314356 (unless you have a pre-production device with an invalid IMEI like 0000000000000).

2. Pseudo-Unique ID, that works on all Android devices
Some devices don't have a phone (eg. Tablets) or for some reason you
don't want to include the READ_PHONE_STATE permission. You can still
read details like ROM Version, Manufacturer name, CPU type, and other
hardware details, that will be well suited if you want to use the ID for
a serial key check, or other general purposes. The ID computed in this
way won't be unique: it is possible to find two devices with the same ID
(based on the same hardware and rom image) but the chances in real
world applications are negligible. For this purpose you can use the
Build class:

String m_szDevIDShort = "" + //we make this look like a valid IMEI
Build.BOARD.length()%+ Build.BRAND.length()% +
Build.CPU_ABI.length()% + Build.DEVICE.length()% +
Build.DISPLAY.length()% + Build.HOST.length()% +
Build.ID.length()% + Build.MANUFACTURER.length()% +
Build.MODEL.length()% + Build.PRODUCT.length()% +
Build.TAGS.length()% + Build.TYPE.length()% +
Build.USER.length()% ; //13 digits

Most of the Build members are strings, what we're doing here is to take their length and transform it via modulo in a digit. We have 13 such digits and we are adding two more in front (35) to have the same size ID like the IMEI (15 digits). There are other possibilities here are well, just have a look at these strings.
Returns something like: 355715565309247 . No special permission are required, making this approach very convenient.

3. The Android ID , considered unreliable because it can
sometimes be null. The documentation states that it "can change upon
factory reset". This string can also be altered on a rooted phone.

  1. String m_szAndroidID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

Returns: 9774d56d682e549c . No special permissions required.

4. The WLAN MAC Address string, is another unique identifier that you can use as a device id. Before you read it, you will need to make sure that your project has the android.permission.ACCESS_WIFI_STATE permission or the WLAN MAC Address will come up as null.

  1. WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
  2. String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();

Returns: 00:11:22:33:44:55 (not a real address since this is a custom ROM , as you can see the MAC address can easily be faked). WLAN doesn't have to be on, to read this value.

5. The BT MAC Address string, available on Android devices with Bluetooth, can be read if your project has the android.permission.BLUETOOTH permission.

  1. BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter
  2. m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  3. String m_szBTMAC = m_BluetoothAdapter.getAddress();

Returns: 43:25:78:50:93:38 . BT doesn't have to be on, to read it.

Combined Device ID
Above, you have here 5 ways of reading a device unique identifier. Some
of them might fail and return null, or you won't be able to use them
because of the special permissions or because the hardware is missing
(phone, bluetooth, wlan).
Nevertheless on all platforms you will find at least one that works. So a
very good idea is to mix these strings, and generate a unique result
out of their sum. To mix the strings you can simply concatenate them,
and the result can be used to compute a md5 hash:

String m_szLongID = m_szImei + m_szDevIDShort + m_szAndroidID+ m_szWLANMAC + m_szBTMAC;
// compute md5
MessageDigest m = null;
try {
m = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
m.update(m_szLongID.getBytes(),,m_szLongID.length());
// get md5 bytes
byte p_md5Data[] = m.digest();
// create a hex string
String m_szUniqueID = new String();
for (int i=;i<p_md5Data.length;i++) {
int b = (0xFF & p_md5Data[i]);
// if it is a single digit, make sure it have 0 in front (proper padding)
if (b <= 0xF) m_szUniqueID+="";
// add number to string
m_szUniqueID+=Integer.toHexString(b);
}
// hex string to uppercase
m_szUniqueID = m_szUniqueID.toUpperCase();

The result has 32 hex digits and it looks like this:

9DDDF85AFF0A87974CE4541BD94D5F55
You can use it to generate any size unique string using hex digits or other sets of characters.

The Serial Number is the ADB Serial Number for Developer.

For Detail:http://android-developers.blogspot.sg/2011/03/identifying-app-installations.html

Android Unique Device ID的更多相关文章

  1. STM32唯一ID(Unique Device ID)的读取方法

    每一个STM32微控制器都自带一个96位的唯一ID,也就是Unique Device ID或称为UID,这个唯一ID在任何情况下都是唯一的且不允许修改.    在开发过程中,可能需要用到这个UID,比 ...

  2. Android设备的ID

    Android的开发者在一些特定情况下都需要知道手机中的唯一设备ID.例如,跟踪应用程序的安装,生成用于复制保护的DRM时需要使用设备的唯一ID.在本文档结尾处提供了作为参考的示例代码片段. 范围 本 ...

  3. android device ID获取

    Android  Device ID是Android用户在Google认证过手机的设备唯一标识,当然国内很多Android手机没有经过Google认证,所以一般没有Google官方Android de ...

  4. android unique identifier

    android get device mac address programmatically http://android-developers.blogspot.jp/2011/03/identi ...

  5. Create new Android Virtual Device时不能创建

    在Create new Android Virtual Device时不能创建... 因为之前有重装过系统,ADT和java都没有更换,不知道是不是有哪里的环境(C盘中的配置)出错了... LOG在下 ...

  6. Alternative to iPhone device ID (UDID)

    Alternative to iPhone device ID (UDID) [duplicate] up vote10down votefavorite 3 Possible Duplicate:U ...

  7. 打开android虚拟机时出现a repairable android virtual device

    打开android虚拟机时出现a repairable android virtual device,虚拟机可以打开但是一直处于开机状态,具体解决方案如下: 解决方案1:换个版本,不要选 CPU/AB ...

  8. Device ID

    参考文章 一.CFUUID (Deprecated) 二.UDID (Deprecated) 三.NSUUID (ios6.0 and later) NSString *uuid = [[NSUUID ...

  9. eclipse安装ADT插件重启后不显示Android SDK Manager和Android Virtual Device Manager图标的一种解决办法

    通常安装,搭建安卓环境后,不显示Android SDK Manager和Android Virtual Device Manager ize解决方法:Eclipse ->window->c ...

随机推荐

  1. 【贪心】Codeforces Round #436 (Div. 2) D. Make a Permutation!

    题意:给你一个长度为n的数组,每个元素都在1~n之间,要你改变最少的元素,使得它变成一个1~n的排列.在保证改动最少的基础上,要求字典序最小. 预处理cnt数组,cnt[i]代表i在原序列中出现的次数 ...

  2. 【点分治】【FFT】Gym - 101234D - Forest Game

    存个求树上每种长度(长度定义为路径上点数)的路径条数的模板:num数组中除了长度为1的以外,都算了2次. 不造为啥FFT数组要开八倍. #include<cstdio> #include& ...

  3. 陈立伟 - MultiCharts快易通(2013年8月2日)

    <MultiCharts快易通> 作 者:陈立伟 译 者: 系 列:寰宇程式交易312--挑战程式交易系列1 出 版:寰宇出版股份有限公司 字 数:千字 阅读完成:2013年8月2日

  4. 免费网站监控服务阿里云监控,DNSPod监控,监控宝,360云监控使用对比

    网站会因为各种原因而导致宕机,具体表现为服务器没有响应,用户打不开网页,域名解析出错,搜索引擎抓取页面失败,返回各种HTTP错误代码.网站宕机可能带来搜索引擎的惩罚,网站服务器不稳定与百度关系文章中就 ...

  5. NServiceBus入门:多个endpoint(Introduction to NServiceBus: Multiple endpoints)

    原文地址:https://docs.particular.net/tutorials/intro-to-nservicebus/3-multiple-endpoints/ 侵删. 目前为止,我们只是在 ...

  6. 实现自动解析properties文件并装配到Bean

    主要实现了,配置的属性就装配, 没有配置的属性不装配 思路: 1 . 通过反射获取类内部所有方法名称 2 . 获取perperties 的key集合 3 .  处理字符串,比较两个匹配,如果匹配成功就 ...

  7. JAVA常见算法题(二十九)

    package com.forezp.util; import java.util.Scanner; /** * 判断输入的5个字符串的最大长度,并输出 * * * @author Administr ...

  8. Openshift部署Zookeeper和Kafka

    部署Zookeeper github网址 https://github.com/ericnie2015/zookeeper-k8s-openshift 1.在openshift目录中,首先构建imag ...

  9. 二十四种设计模式:解释器模式(Interpreter Pattern)

    解释器模式(Interpreter Pattern) 介绍给定一个语言, 定义它的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中的句子. 示例有一个Message实体类,某个类对它的 ...

  10. 如何在Visual Studio中加载web load test的后缀为.ltrar的结果文件

    1. From a Web performance and load test project, open a load test.   2. On the embedded toolbar, cho ...