Android的唯一的序列号 [英] Android Unique Serial Number

查看:264
本文介绍了Android的唯一的序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序为目标的A​​ndr​​oid 4.0(API 14)及以上。

我要寻找一个序列号,也就是每台设备独特的和不断的持续(模具与设备,工厂重置后不改变)。

我发现很多有关Android设备的唯一标识符在网络上的结果,但很少的 android.os.Build.SERIAL 数。

到目前为止,我消除了使用的 ANDROID_ID ,因为它可能出厂重置后更改。我也消除了使用 IMEI ,因为Android设备可能是非的手机。我无法使用WiFi或蓝牙的 MAC地址,因为该设备可能不具备这样的硬件和/或该MAC地址可能无法读取如果未启用的硬件(根据我在网上找到)

我想我可能会去为Android设备的序列号。

这是方便使用的 android.os.Build.SERIAL (因为它被添加在API 9级,并且不需要任何额外的权限)。

我的问题是:

  • 考虑到我的应用程序的目标的Andr​​oid 4.0(API 14)及以上,是在 android.os.Build.SERIAL 作为唯一的每个设备的Andr​​oid设备数量?

  • 目前, android.os.Build.SERIAL 表示文档:硬件序列号,如果有的话。只有字母数字,不区分大小写。 这是否意味着序列号可能无法使用?

  • 还有什么能满足上述条件的另一种选择?

解决方案
  

考虑到我的应用程序的目标的Andr​​oid 4.0(API 14)及以上,是android.os.Build.SERIAL号唯一的每个设备的Andr​​oid设备?

根据这个有用的<一个href="http://android-developers.blogspot.com/2011/03/identifying-app-installations.html">article, android.os.Build.SERIAL 是唯一的(如果可用)。 从文章:

设备没有电话需要在这里报告唯一的设备ID;有些手机可以这样做也。

  

这是否意味着序列号可能无法使用?

正确,则可能无法使用。请注意,他们说的设备没有电话是必需的。,所以才没有电话(如无线仅平板电脑)的设备需要提供一个 SERIAL 数,但也有一些手机还是做(比如Nexus的4)。

文件肯定是缺乏有关这个话题,但是从措辞有可能只被要求没有电话设备提交一个唯一的ID,而手机,就提交一份可能不是唯一的。

  

还有什么能满足上述条件的另一种选择?

有关你的情况,我认为最好的办法是为 DEVICEID (IMEI,或什么不可以),如果 DEVICEID 不存在,那么您还原到使用 android.os.Build.SERIAL (因为这可能是一个平板电脑),像这样:

 公共静态字符串getDeviceId(上下文的背景下){
    最后弦乐的DeviceID =((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE))getDeviceId()。
    如果(DEVICEID!= NULL){
        返回的DeviceID;
    } 其他 {
        返回android.os.Build.SERIAL;
    }
}
 

请记住使用 DEVICEID 您需要的权限 android.permission.READ_PHONE_STATE

于是,因为你的应用程序的minSDK是14,你可以放心地使用该领域 android.os.Build.SERIAL 。如果我们假设,如果没有电话设备真正做到始终提供唯一的ID在 SERIAL 那么我认为这将是对始终得到一个唯一的设备ID(栏的任何错误一个安全的赌注当然)。

I am developing an android application that targets Android 4.0 (API 14) and above.

I am looking for a serial number that is unique per device and that persists for ever (dies with the device, does not change after factory resets).

I have found lots of results on the web concerning unique identifiers for android devices, but very little on the android.os.Build.SERIAL number.

So far, I eliminated the use of the ANDROID_ID because it might change after factory resets. I also eliminated the use of the IMEI because the android device might be non-phone. I cannot use the wifi or bluetooth MAC ADDRESS because the device might not have such hardware and/or such mac addresses might not be readable if the hardware is not enabled (based on what I found on the web).

I believe I might go for the android device serial number.

It is easily accessible using android.os.Build.SERIAL (since it is added in API level 9 and does not need any additional permission).

My questions are :

  • Taking into consideration that my application targets Android 4.0 (API 14) and above, is the android.os.Build.SERIAL number for the android devices unique for each device ?

  • Currently, documentation of android.os.Build.SERIAL indicates : A hardware serial number, if available. Alphanumeric only, case-insensitive. Does this mean that the serial number might not be available ?

  • What could be another alternative that meets the conditions mentioned above ?

解决方案

Taking into consideration that my application targets Android 4.0 (API 14) and above, is the android.os.Build.SERIAL number for the android devices unique for each device ?

According to this useful article, android.os.Build.SERIAL should be unique if it is available. From the article:

Devices without telephony are required to report a unique device ID here; some phones may do so also.

Does this mean that the serial number might not be available ?

Correct, it may not be available. Notice that they say "Devices without telephony are required...", so only devices without "telephony" (like wifi only tablets) are required to supply a SERIAL number, although some phones still do (like the Nexus 4).

Documentation is definitely lacking on this topic, but from the wording it's possible that only "devices without telephony" are required to submit a unique ID, while phones that do submit one might not be unique.

What could be another alternative that meets the conditions mentioned above ?

For your situation I think your best bet is to first check for a deviceId (IMEI, or what not) and if deviceId doesn't exist then you fallback to using android.os.Build.SERIAL (since this is probably a tablet) like so:

public static String getDeviceId(Context context) {
    final String deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
    if (deviceId != null) {
        return deviceId;
    } else {
        return android.os.Build.SERIAL;
    }
}

Keep in mind to use deviceId you need the permission android.permission.READ_PHONE_STATE.

So since your app's minSDK is 14, you can safely use the field android.os.Build.SERIAL. And if we assume that devices without telephony truly do always provide unique ids in SERIAL then I think this would be a safe bet on always getting a unique device id (bar any bugs of course).

这篇关于Android的唯一的序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆