Is android.os.Build.SERIAL unique?

烂漫一生 提交于 2019-12-18 12:51:22

问题


I would like to use a unique id for android device that works for phone and Tablet. (IMEI doesn't work with no SIM card device and sometime MAC Address return null)

I'm not sure is android.os.Build.SERIAL unique or not.

Does anyone know about this?

Thanks, Regards.


回答1:


Yes, but note that it was only added in API level 9, and it may not be present on all devices. To get a unique ID on earlier platforms, you'll need to read something like the MAC address or IMEI.

Generally, try reading all the possible IDs, and use whichever are available. See this article for guidance.




回答2:


You can use Build serial and android ID to make your own unique id.

String serial =    Build.SERIAL;
String android_id =Secure.getString(context.getContentResolver(),
                   Secure.ANDROID_ID);

String myKey=serial +android_id ;



回答3:


Serial was only exposed in API:9. but you can get it in older versions using reflection. However the docs mention "if available" so I guess don't rely on it.

String deviceSerial = (String) Build.class.getField("SERIAL").get(
                    null);



回答4:


I think for unique Id you should used android Id. following is code to get Android Id.

String android_id = Secure.getString(this.getContentResolver(),
            Secure.ANDROID_ID);
Log.d("Android","Android ID : "+android_id);



回答5:


If it is there, then it is expected to be unique. But there is no guarantee that this property is set. Also it is API 9. Unfortunately there's no easy way to uniquely identify the device. Some properties like said SERIAL can be present, others like ANDROID_ID as NOT unique, some other like MAC depends on presence of WIFI or its state (if wifi module is off, the you may not be able to read its MAC). Some like IMEI cannot be read even device got phone module. So the best approach is to gather as much data as you can, and try to build something you could most likely consider unique device ID




回答6:


What about a combination of MAC, IMEI and SERIAL ?

You just have to deal with the fact that they all could be non existant esp. on older phones without SIM.

I just find it odd that MAC would return null. This should not be possible imho, as it makes no sense that a mobile device has no MAC.

There are 2 MAC addresses possible but they can be non accessible in some cases.



来源:https://stackoverflow.com/questions/13471283/is-android-os-build-serial-unique

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!