如何查看 Google Play 保护状态?

How to check Google Play Protect status?

我正在创建一个防病毒软件,我想知道 Google Play Protect 是启用还是禁用?我在 Android Studio 中使用 Java。访问此信息是否需要任何权限?

您可以使用 SafetyNet Verify Apps API 检查 Google Play Protect(也称为验证应用程序)是否已启用(请参阅 link 了解更多详细信息,包括 Kotlin 版本和如果它被禁用,提示用户启用它的选项。

这是一个异步 API,因此您必须编写回调,例如:

SafetyNet.getClient(context)
    .isVerifyAppsEnabled()
    .addOnCompleteListener(new OnCompleteListener<VerifyAppsUserResponse>() {
        @Override
        public void onComplete(Task<VerifyAppsUserResponse> task) {
            if (task.isSuccessful()) {
                VerifyAppsUserResponse result = task.getResult();
                if (result.isVerifyAppsEnabled()) {
                    // It's enabled, handle that case here
                } else {
                    // It's not enabled, handle that case here
                }
            } else {
                // An error occurred, we don't know whether it's enabled
            }
        }
    });

如果您从 ActivityService 调用它,context 参数就是您的 this