使用 SafetyNet Attestation API 的安全环境检查 android 无法正常工作,因为它没有在成功或失败回调时获得回调

Safety environment check in android using SafetyNet Attestation API is not working as it not getting callback on success or failure callback

为了安全环境检查 android 我使用的是

https://developer.android.com/training/safetynet/attestation.html

SafetyNet.getClient(this).attest(nonce, API_KEY)
   .addOnSuccessListener(this,successListner)
   .addOnFailureListener(this,failureListener)

为此我收到失败回调 网络错误 null。任何人都可以对此有所了解吗?

但是https://medium.com/@hargoyal/secure-android-app-with-safetynet-8e367a1c8ad0

SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
                .setResultCallback(new ResultCallback<SafetyNetApi.AttestationResult>() {
                    @Override
                    public void onResult(SafetyNetApi.AttestationResult result) {
                        Status status = result.getStatus();
                        if (status.isSuccess()) {
                            decodeJws(result.getJwsResult());
                            // Indicates communication with the service was successful.
                            // Use result.getJwsResult() to get the result data.
                        } else {
                            // An error occurred while communicating with the service.
                        }
                    }
                });

此方法有效,但 SafetyNet.SafetyNetApi 已弃用。

重新检查 API 键或创建一个新键,例如 here。我遇到了同样的问题,问题是我将密钥限制为错误的包名称。

  • Go to the Library page in the Google APIs Console.
  • Search for the Android Device Verification API. When you've found the API, click on it. The Android Device Verification API dashboard screen appears.
  • If the API isn't already enabled, click Enable.
  • If the Create credentials button appears, click on it to generate an API key. Otherwise, click the All API credentials drop-down list and select the API key that is associated with the project for which the Android Device Verification API is enabled.
  • In the sidebar on the left, click Credentials. Copy the API key that appears.