如何开启和检查Play Protect是否已启用或禁用?

4
    minSdkVersion 18
    targetSdkVersion 27

使用下面的代码,我可以打开Google设置页面。
private static final String GOOGLE_SETTINGS_COMPONENT = "com.google.android.gms";
private static final String GOOGLE_SETTINGS_ACTIVITY = ".app.settings.GoogleSettingsActivity";
Intent i = new Intent();
i.setClassName(GOOGLE_SETTINGS_COMPONENT,GOOGLE_SETTINGS_COMPONENT + GOOGLE_SETTINGS_ACTIVITY);
try {
      startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
      Toast.makeText(getApplicationContext(), "Activity Not Found", Toast.LENGTH_LONG).show();
 }
  1. 是否可以直接打开Google设置-->安全性-->Google Play 保护页面。
  2. 如何检查扫描设备以查找安全威胁选项是否已启用或禁用?
2个回答

9

1)是否可以直接打开Google设置-->安全-->Google Play保护页面?

您可以使用com.google.android.gms.security.settings.VerifyAppsSettingsActivity意图直接启动Play Protect屏幕,如下所示。

val intent = Intent()
intent.setComponent(ComponentName("com.google.android.gms", "com.google.android.gms.security.settings.VerifyAppsSettingsActivity"))
startActivity(intent)

这里是Playstore APK的元数据,您可以查看所有可用的活动。

2) 如何检查“扫描设备以查找安全威胁”选项是否已启用或禁用?

开发人员可以从SafetyNet Verify Apps API中获取类似的安全洞察力,了解用户设备上已安装应用程序的情况。这个新的API套件让开发者确定用户的设备是否受到Google Play Protect的保护,鼓励尚未使用Google Play Protect的用户启用它,并识别任何已知的潜在有害应用(PHA),这些应用已经安装在设备上。

这些API特别适用于开发应用程序的开发人员,因为他们的应用可能会受到已安装PHA设备的影响。通过isVerifyAppsEnabled()确定Google Play Protect已启用,可以为开发人员提供额外的保证,表明设备更有可能是干净的。如果设备未启用Google Play Protect,则开发人员可以要求用户使用enableVerifyApps()启用Google Play Protect。启用Google Play Protect后,开发人员可以使用listHarmfulApps()方法确定用户设备上是否安装了任何潜在的有害应用程序。这个易于使用的功能套件不需要API密钥和请求配额。

编译com.google.android.gms:play-services-safetynet:11.6.0并使用以下代码。

确定应用程序验证是否已启用
SafetyNet.getClient(this)
    .isVerifyAppsEnabled()
    .addOnCompleteListener(new OnCompleteListener<VerifyAppsUserResponse>() {
        @Override
        public void onComplete(Task<VerifyAppsUserResponse> task) {
            if (task.isSuccessful()) {
                VerifyAppsUserResponse result = task.getResult();
                if (result.isVerifyAppsEnabled()) {
                    Log.d("MY_APP_TAG", "The Verify Apps feature is enabled.");
                } else {
                    Log.d("MY_APP_TAG", "The Verify Apps feature is disabled.");
                }
            } else {
                Log.e("MY_APP_TAG", "A general error occurred.");
            }
        }
    });

请求启用应用程序验证。
SafetyNet.getClient(this)
    .enableVerifyApps()
    .addOnCompleteListener(new OnCompleteListener<VerifyAppsUserResponse>() {
        @Override
        public void onComplete(Task<VerifyAppsUserResponse> task) {
            if (task.isSuccessful()) {
                VerifyAppsUserResponse result = task.getResult();
                if (result.isVerifyAppsEnabled()) {
                    Log.d("MY_APP_TAG", "The user gave consent " +
                          "to enable the Verify Apps feature.");
                } else {
                    Log.d("MY_APP_TAG", "The user didn't give consent " +
                          "to enable the Verify Apps feature.");
                }
            } else {
                Log.e("MY_APP_TAG", "A general error occurred.");
            }
        }
    });

为了更好的保护,开发人员应该同时使用证明API和新的Verify Apps API。首先使用证明API来确认设备没有被修改过。一旦Android系统可信,就可以信任Verify Apps API的结果。
P.S. 在使用API之前,请阅读其他条款和条件

谢谢Anoop。有没有可能在单个按钮中禁用Play Protect?而不是进入页面? - Gvtha
调用“com.google.android.gms.security.settings.VerifyAppsSettingsActivity”似乎无法正常工作(ActivityNotFoundException)。 我使用了startActivity(Intent("com.google.android.gms.security.settings.VerifyAppsSettingsActivity")) 我做错了吗?(我的奥利奥手机有Google Protect菜单) - Youngjae
谢谢分享。有没有办法通过使用adb命令行禁用Play Protect? - Corey

0

In JAVA

  Intent i = new Intent();
i.setClassName("com.google.android.gms", "com.google.android.gms.security.settings.VerifyAppsSettingsActivity" );
try {
    startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(getApplicationContext(), "Activity Not Found", Toast.LENGTH_LONG).show();
}

当前您的回答写得不太清楚。请 [编辑] 添加更多细节,以帮助他人了解它如何回答所提出的问题。您可以在 帮助中心 中找到关于如何编写良好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接