android device ID獲取


Android  Device ID是Android用戶在Google認證過手機的設備唯一標識,當然國內很多Android手機沒有經過Google認證,所以一般沒有Google官方Android device ID,所以沒法充Google play電腦端下載apk:

下面我代碼我在Google的親兒子nexus 6和nexus 5上測試通過可以獲取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;
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM