1

Apiexception with status code 7 occurs due to network error but that doesn't seem to be the issue since internet is working fine on the device.

Code snippet-

SafetyNet.getClient(this).attest(nonce, API_KEY)
                .addOnSuccessListener(this,
                        new OnSuccessListener<SafetyNetApi.AttestationResponse>() {
                            @RequiresApi(api = Build.VERSION_CODES.KITKAT)
                            @Override
                            public void onSuccess(SafetyNetApi.AttestationResponse response) {
                                mResult = response.getJwsResult();
                                Log.i(TAG, "safetynet result is" + mResult + "\n");
                                mainres = initialDataExtraction(response.getJwsResult());
                                Log.i(TAG, "Main result is" + mainres + "\n");
                            }
                        })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        if (e instanceof ApiException) {
                            ApiException apiException = (ApiException) e;
                            int statuscode = apiException.getStatusCode();
                            Log.i(TAG,"EXCEPTION CODE: "+statuscode);
                        } else {
                            Log.d(TAG, "Error: " + e.getMessage());
                        }
                    }
                });

4 Answers4

1

The issue was with my API key. I was using the API key of a colleague which was restricted. Using my own API key it worked fine.

0

My issue was i registered SHA1 from play console but not SHA1 in my android studio.

Bhimbim
  • 1,348
  • 2
  • 19
  • 15
0

We have this error when the Safetynet API quotas are exceeded. The default quota is 10_000 requests per day, reset at midnight.

Ben-J
  • 1,084
  • 8
  • 24
0

Downgrading the com.google.android.gms:play-services-safetynet dependency on the app's build.gradle from 18.0.1 to 18.0.0 fixed it for me.

Do still double-check your API key restrictions (SHA1, package name) since they might cause this error too if there's something wrong with them, but downgrading the API a notch fixed it for me.

Also, double-check if you're reading the APK key from your keys file correctly, try hard-coding the API key into the class as a String and see if it works, of course don't do this in production code, you must hide your API key in release.

M.Ed
  • 969
  • 10
  • 12
  • 1
    It's really important to verify the SHA1 hash if your API key is restricted, the DEBUG SHA1 code MUST be added for EVERY machine which compiles a debug version of your APK. – Akhha8 Aug 02 '22 at 00:06
  • 1
    @Akhha8 yes, that too, every local machine's debug SHA1 certs must manually be added to the API key restrictions. – M.Ed Aug 02 '22 at 08:21