ANDROID_ID API 26 上的 abd 和代码不同

ANDROID_ID different in abd and in code on API 26

在模拟器上使用 API 25:

adb shell settings put secure android_id 8af8770a27cfd182
adb shell settings get secure android_id //gives 8af8770a27cfd182
Secure.getString(context.getContentResolver(), Secure.ANDROID_ID) //gives 8af8770a27cfd182

在模拟器上使用 API 26:

adb shell settings put secure android_id 8af8770a27cfd182
adb shell settings get secure android_id //gives 8af8770a27cfd182
Secure.getString(context.getContentResolver(), Secure.ANDROID_ID) //gives 6e4f84f5513b80e1

我已经阅读了 ANDROID_ID 在 API 25 和 26 之间的变化,但为什么 adb 和代码给我不同的结果?

更新:

创建了一个简单的应用程序来消除旧应用程序的复杂性。新应用有一个主 activity,上面有一个按钮:

package com.example.diolaj01.testandroidid;

import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

protected void GetAndroidId(View view){
    Log.e("myDebugTag", Settings.Secure.getString(view.getContext().getContentResolver(),
            Settings.Secure.ANDROID_ID));

}
}

当点击带有 API 25 的设备上的按钮时,我得到的值与从 adb 请求 ANDROID_ID 时得到的值相同:

adb shell settings get secure android_id

如果我更改 android_id 我仍然会在控制台中使用按钮和使用 adb 获得更新的。

在带有 API 26 的设备上单击按钮时,我得到的值与使用 adb 时得到的值不同。如果我使用 adb 更改 android_id,我将在使用 adb 但不使用按钮时获得更新的值。

来自https://developer.android.com/about/versions/oreo/android-8.0-changes.html#privacy-all

Privacy Android 8.0 (API level 26) makes the following privacy-related changes to the platform.

The platform now handles identifiers differently.

For apps that were installed prior to an OTA to a version of Android 8.0 (API level 26) (API level 26), the value of ANDROID_ID remains the same unless uninstalled and then reinstalled after the OTA. To preserve values across uninstalls after OTA, developers can associate the old and new values by using Key/Value Backup.

For apps installed on a device running Android 8.0, the value of ANDROID_ID is now scoped per app signing key, as well as per user. The value of ANDROID_ID is unique for each combination of app-signing key, user, and device. As a result, apps with different signing keys running on the same device no longer see the same Android ID (even for the same user).

The value of ANDROID_ID does not change on package uninstall or reinstall, as long as the signing key is the same (and the app was not installed prior to an OTA to a version of Android 8.0).

The value of ANDROID_ID does not change even if a system update causes the package signing key to change.

On devices shipping with Google Play services and Advertising ID, you must use Advertising ID. A simple, standard system to monetize apps, Advertising ID is a unique, user-resettable ID for advertising. It is provided by Google Play services.

Other device manufacturers should continue to provide ANDROID_ID.

shell 用户与您应用的用户 ID 不同 - 因此存在差异。