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之前,请阅读
其他条款和条件。
startActivity(Intent("com.google.android.gms.security.settings.VerifyAppsSettingsActivity"))
我做错了吗?(我的奥利奥手机有Google Protect菜单) - Youngjaeadb
命令行禁用Play Protect? - Corey