android device id confusion

前端 未结 5 1703
-上瘾入骨i
-上瘾入骨i 2020-12-01 00:47

If I dial * # * # 8 2 5 5 # * # * ,

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 01:21

    Found on the web:

    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);
    
        if (!c.moveToFirst() || c.getColumnCount() < 2)
            return null;
    
        try {
            return Long.toHexString(Long.parseLong(c.getString(1)));
        } catch (NumberFormatException e) {
            return null;
        }
    }
    

    Add permission:

    
    

    However, I doubt that is a documented ID and I would be carefull because that might not work if GTalk gets updated.

    Source: http://blog.codepainters.com/2012/01/17/how-to-obtain-gtalk-android-id/

    Also worth having a look at: http://www.toxicbakery.com/android-development/getting-google-auth-sub-tokens-in-your-android-applications/

提交回复
热议问题