我们正在尝试将安全网 API 添加到我们的应用程序中。当我们在真实设备上测试时,一切正常,但是在模拟器上测试时,安全网服务器没有响应。API 的目的是检测模拟设备,所以不知道为什么它不能在模拟器上工作。
以下是 API 调用:
SafetyNet.getClient(activity).attest(getRequestNonce(nonceData), "<Key-here>").addOnSuccessListener(activity, new OnSuccessListener() {
public void onSuccess(AttestationResponse response) {
String[] jwtParts = response.getJwsResult().split("\\.");
if(jwtParts.length == 3) {
String sharedpreferences = new String(Base64.decode(jwtParts[1], 0));
SharedPreferences editor = context.getSharedPreferences("DecodedPayload", 0);
Editor editor1 = editor.edit();
editor1.putString("decodedPayload", sharedpreferences);
editor1.commit();
Log.d("ContentValues", "The Safety net response is: " + sharedpreferences);
} else {
SharedPreferences sharedpreferences1 = context.getSharedPreferences("DecodedPayload", 0);
Editor editor2 = sharedpreferences1.edit();
editor2.putString("decodedPayload", "CND");
editor2.commit();
Log.d("ContentValues", "The safety net response could not be decoded");
}
}
}).addOnFailureListener(activity, new OnFailureListener() {
public void onFailure(@NonNull Exception e) {
if(e instanceof ApiException) {
ApiException apiException = (ApiException)e;
Log.d("ContentValues", "Error while fetching safety net result: " + ((ApiException)e).getStatusCode() + " " + ((ApiException)e).getStatusMessage());
SharedPreferences sharedpreferences = context.getSharedPreferences("DecodedPayload", 0);
Editor editor = sharedpreferences.edit();
editor.putString("decodedPayload", "ERR");
editor.commit();
Log.d("ContentValues", "The safety net response could not be decoded");
} else {
Log.d("ContentValues", "Unknown Error while fetching safety net results: " + e.getMessage());
}
}
});
}
即使等待了 30 秒,也没有一个处理程序得到响应。有人可以帮忙吗。