我怎样才能获取Android设备ID,我得到拨打 *#*# #*#*我怎样才能获得Android设备ID,我得到拨打 “*#*#8255#*#*”
我使用下面的代码,但它不返回相同的......我想什么
String android_id = Secure.getString(getActivity()
.getContentResolver(), Secure.ANDROID_ID);
我怎样才能获取Android设备ID,我得到拨打 *#*# #*#*我怎样才能获得Android设备ID,我得到拨打 “*#*#8255#*#*”
我使用下面的代码,但它不返回相同的......我想什么
String android_id = Secure.getString(getActivity()
.getContentResolver(), Secure.ANDROID_ID);
我想你也许试过代码返回一个动态的ID。尝试这个。
private static final Uri URI = Uri.parse(“content://com.google.android.gsf.gservices”); private static final String ID_KEY =“android_id”;
String getAndroidId(Context ctx) {
String[] params = { ID_KEY };
Cursor c = ctx.getContentResolver()
.query(URI, null, null, params, null);
try{
if (!c.moveToFirst() || c.getColumnCount() < 2){
return null;
}
}catch(Exception e){
return null;
}
try {
Toast.makeText(ctx, Long.toHexString(Long.parseLong(c.getString(1))), 500).show();
System.out.println("android id " + Long.toHexString(Long.parseLong(c.getString(1))));
return Long.toHexString(Long.parseLong(c.getString(1)));
} catch (NumberFormatException e) {
return null;
}
}
在上面的代码Long.toHexString(的Long.parseLong(c.getString(1))),则返回该机器人设备ID。
这是一个有趣的问题,并已在此问题中讨论过:http://stackoverflow.com/questions/13744565/android-device-id-confusion –
对不起,但该链接不完全是我一直在寻找的东西! ! – Neeraj