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

牧云@^-^@ 提交于 2019-12-20 02:32:40

问题


For saftey environment check in android I was using

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

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

for which I am getting failure callback with network error null. Can anybody please throw some light on this ?

but 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.
                        }
                    }
                });

this approach is working but SafetyNet.SafetyNetApi is deprecated.


回答1:


Recheck the API key or create a new one like here. I was having the same issue and the problem was that I was restricting the key to the wrong package name.

  • 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.


来源:https://stackoverflow.com/questions/47068393/safety-environment-check-in-android-using-safetynet-attestation-api-is-not-worki

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!