How to check if “verify app” is enabled or disable

2020-07-24 04:22发布

问题:

I've a security requirement to alert users if google's "verify app" is disabled on app launch. The problem is that I dont know any way to check whether "verify app" is disabled or not.

I tried to use the code below, but it's always returning 1.

        int verifierInt = -1;
        if (Build.VERSION.SDK_INT >= 17) {
            verifierInt = Settings.Global.getInt(context.getContentResolver(), "package_verifier_enable", -1);
        } else if (Build.VERSION.SDK_INT >= 14) {
            verifierInt = Settings.Secure.getInt(context.getContentResolver(), "verifier_enable", -1);
        } else {
            // No package verification option before API Level 14
        }
        boolean isVerifyAppEnabled = verifierInt == 1;

Also, as a requirement, want user to be navigated to the "verifiy app" settings if this feature is disabled.

回答1:

You should check like this:

Settings.Global.getInt(context.getContentResolver(), "verifier_verify_adb_installs", -1);


回答2:

Reading preferences value for google Verify won't work. Please use below SaftyNet callbacks to verify google protect.

SafetyNet.getClient(context)
                .isVerifyAppsEnabled()
                .addOnCompleteListener(new OnCompleteListener<SafetyNetApi.VerifyAppsUserResponse>() {
                    @Override
                    public void onComplete(@NonNull Task<SafetyNetApi.VerifyAppsUserResponse> task) {
---
}
});