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; } }