由于网络错误,出现状态代码为 7 的 Apiexception,但这似乎不是问题,因为互联网在设备上运行良好。
代码片段-
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());
}
}
});