android device ID acquisition

Android Device ID is an Android cell phone user authentication in the Google device is unique, of course, many domestic Android phone is not certified by Google, it is generally not the official Google Android device ID, so I can not charge Google play computer terminal download apk:

Below the code I kissed my son on Google's nexus 6 and the nexus 5 on the test can get Android Device ID:

private static String getGsfAndroidId(Context context) 
    {
        Uri URI = Uri.parse("content://com.google.android.gsf.gservices");
        String ID_KEY = "android_id";
        String params[] = {ID_KEY};
        Cursor c = context.getContentResolver().query(URI, null, null, params, null);
        if (!c.moveToFirst() || c.getColumnCount() < 2)
            return null;
        try 
        {
            return Long.toHexString(Long.parseLong(c.getString(1)));
        } 
        catch (NumberFormatException e) 
        {
            return null;
        }
    }

 

Reproduced in: https: //www.cnblogs.com/ronaldHU/p/Android.html

Guess you like

Origin blog.csdn.net/weixin_34319111/article/details/94272147