I'm trying to get android unique id i'm using this code to get android unique id
String phoneID = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
when i use this code on sdk version 2.3 on emulator it work fine and return randomly generated android id, but when i use similar code in sdk version 2.0 it will return null,
i try this code also but same res开发者_运维知识库ult,
String phoneID = System.getString(getContext().getContentResolver(), System.ANDROID_ID);
is there any another way to get android unique id? I'm testing my application on emulator.
See Stackoverflow - how-to-find-serial-number-of-android-device for other ways of getting unique ID for android device. Seva's comment contains info about why you're getting a NULL for ANDROID_ID:
This ID comes from the Google account associated with the phone. The simulator typically does not have one. A real phone might not have one, either. Also, it's documented as "can change upon factory reset", and it can be changed arbitrarily anytime on a rooted phone.
精彩评论