Getting Udid in android

大憨熊 提交于 2019-12-18 03:45:29

问题


I am developing an android application in which I want to get UDID of android emulator. How can i do it?

Thanks in advance, Tushar


回答1:


I'm not sure if this is what you're after but you could use: Settings.Secure.ANDROID_ID

public class YourActivity extends Activity {
    //...Omitted code
    public String getId() {
        String id = android.provider.Settings.System.getString(super.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
        return id;
    }
}

Note that this isn't an IMEI number, if you need this use getDeviceId()




回答2:


You can do this using the TelephonyManager and the method getDeviceID(). But unfortunately I think for Emulator it will always return null.

Context.getSystemService(Context.TELEPHONY_SERVICE).getDeviceID();

Don't forget to set the permission that is required for that:

Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones. Return null if device ID is not available. Requires Permission: READ_PHONE_STATE

If you want a unique ID as a hex String you might also be interested in:

http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID




回答3:


Have you tried Ti.Platform.id ? That returns a value for me in the emulator.



来源:https://stackoverflow.com/questions/5429916/getting-udid-in-android

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