获取android设备唯一编号_获取Android设备硬件序列号

本文介绍了如何在Android设备上获取硬件序列号,而非ANDROID_ID或Build.SERIAL。通过调用SystemProperties类的方法,可以获取到大多数三星设备的硬件序列号。对于不同型号的三星设备,可能需要使用'sys.serialnumber'或'rيل.serialnumber'来获取。
摘要由CSDN通过智能技术生成

I need to get the hardware serial code of Android device where my app is installed. This hardware serial number is the one that you can see on Settings > About Device > Status > Serial number.

I though I would get it using Settings.Secure.ANDROID_ID or android.os.Build.SERIAL, but neither of them worked, meaning that they didn't give me unique identifier I'm looking for. For instance android.os.Build.SERIAL got me the unique ID shown on ADB when you run the command adb devices.

Notice that the goal of this question is not to find another unique identifier that could help me, it's only about getting the device hardware serial number.

Thanks for the help.

EDIT:

Please be clear that I'm not looking for the value provided by the String android.os.BUILD.SERIAL. I know how to get that value but I'm not interested in it.

I have a Samsung device, therefore, the serial number they used is different than the one provided by android.os.BUILD.SERIAL.

解决方案

The solution is very simple:

Class> c = Class.forName("android.os.SystemProperties");

Method get = c.getMethod("get", String.class, String.class);

serialNumber = (String) get.invoke(c, "sys.serialnumber", "Error");

if(serialNumber.equals("Error")) {

serialNumber = (String) get.invoke(c, "ril.serialnumber", "Error");

}

This will get you the serial number of most samsung devices. I use the "sys.serialnumber" value to get the serial number of my SM-T210 (Galaxy Tab 3) and SM-T230 (Galaxy Tab 4) tablets, but probably works with a lot more Samsung tablets. The "ril.serialnumber" is to get the value on my Samsung GT-I8550L (Galaxy Win).

I hope this helps.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值