android 设备唯一码的获取,Cpu号,Mac地址
2017-06-24 00:24
525 查看
开发Android应用中,我们常常需要设备的唯一码来确定客户端。
Android 中的几中方法,使用中常常不可靠
1. DEVICE_ID
假设我们确实需要用到真实设备的标识,<wbr>可能就需要用到DEVICE_ID。通过 TelephonyManager.getDeviceId()<wbr>获取,它根据不同的手机设备返回IMEI,<wbr>MEID或者ESN码.</wbr></wbr></wbr>
缺点:在少数的一些设备上,该实现有漏洞,会返回垃圾数据
2. MAC ADDRESS
我们也可以通过Wifi获取MAC ADDRESS作为DEVICE ID
缺点:如果Wifi关闭的时候,硬件设备可能无法返回MAC ADDRESS.。
3. Serial Number
android.os.Build.SERIAL直接读取
缺点:在少数的一些设备上,会返回垃圾数据
4. ANDROID_ID
ANDROID_<wbr>ID是设备第一次启动时产生和存储的64bit的一个数,</wbr>
缺点:当设备被wipe后该数改变, 不适用。
android 底层是 Linux,我们还是用Linux的方法来获取:
1 cpu号:
文件在:/proc/cpuinfo
通过Adb shell 查看:
adb shellcat /proc/cpuinfo
2 mac 地址
文件路径/sys/class/net/wlan0/address
adb shellcat/sys/class/net/wlan0/address
xx:xx:xx:xx:xx:aa
这样可以获取两者的序列号,
方法确定,剩下的就是写代码了
以Mac地址为例:
String getMac() {
String macSerial = null;
String str = "";
try {
Process pp = Runtime.getRuntime().exec(
"cat /sys/class/net/wlan0/address ");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (; null != str;) {
str = input.readLine();
if (str != null) {
macSerial = str.trim();// 去空格
break;
}
}
} catch (IOException ex) {
// 赋予默认值
ex.printStackTrace();
}
return macSerial;
}
Android 中的几中方法,使用中常常不可靠
1. DEVICE_ID
假设我们确实需要用到真实设备的标识,<wbr>可能就需要用到DEVICE_ID。通过 TelephonyManager.getDeviceId()<wbr>获取,它根据不同的手机设备返回IMEI,<wbr>MEID或者ESN码.</wbr></wbr></wbr>
缺点:在少数的一些设备上,该实现有漏洞,会返回垃圾数据
2. MAC ADDRESS
我们也可以通过Wifi获取MAC ADDRESS作为DEVICE ID
缺点:如果Wifi关闭的时候,硬件设备可能无法返回MAC ADDRESS.。
3. Serial Number
android.os.Build.SERIAL直接读取
缺点:在少数的一些设备上,会返回垃圾数据
4. ANDROID_ID
ANDROID_<wbr>ID是设备第一次启动时产生和存储的64bit的一个数,</wbr>
缺点:当设备被wipe后该数改变, 不适用。
android 底层是 Linux,我们还是用Linux的方法来获取:
1 cpu号:
文件在:/proc/cpuinfo
通过Adb shell 查看:
adb shellcat /proc/cpuinfo
2 mac 地址
文件路径/sys/class/net/wlan0/address
adb shellcat/sys/class/net/wlan0/address
xx:xx:xx:xx:xx:aa
这样可以获取两者的序列号,
方法确定,剩下的就是写代码了
以Mac地址为例:
String getMac() {
String macSerial = null;
String str = "";
try {
Process pp = Runtime.getRuntime().exec(
"cat /sys/class/net/wlan0/address ");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (; null != str;) {
str = input.readLine();
if (str != null) {
macSerial = str.trim();// 去空格
break;
}
}
} catch (IOException ex) {
// 赋予默认值
ex.printStackTrace();
}
return macSerial;
}
相关文章推荐
- android 设备唯一码的获取,Cpu号,Mac地址
- android 设备唯一码的获取,Cpu号,Mac地址
- android 设备唯一码的获取,Cpu号,Mac地址
- android 设备唯一码的获取,Cpu号,Mac地址
- 获取android 设备的cpu gpu信息 mac地址
- Android中获取设备IP、MAC地址
- [Android开发]android 设备唯一码的获取,Cpu号,Mac地址
- android 设备唯一码的获取,Cpu号,Mac地址
- android 获取设备IP和Mac地址
- android UDID获取:android 设备SN的获取 续 android 设备唯一码的获取,Cpu号,Mac地址
- android 设备唯一码的获取,Cpu号,Mac地址
- android 获取设备信息的IP地址和Mac地址—亲测无误!!
- android 设备唯一码的获取,Cpu号,Mac地址
- android设备唯一码的获取,cpu号,mac地址
- android设备唯一码的获取,cpu号,mac地址
- android 获取设备IP和Mac地址
- android 获取设备的IP和Mac地址
- 关于android设备wifi-mac地址的获取
- Android 设备唯一标识符之 MAC 地址
- android 设备唯一码的获取,Cpu号,Mac地址