尝试在最新的Play-Services v11.0.1中证明SafetyNetClient.attest(...)时,客户端出错并返回ApiException。
代码段:
byte[] nonce = getRequestNonce();
String apiKey = "<api key>";
mSafetyNetClient.attest(nonce, apiKey)
.addOnCompleteListener(new OnCompleteListener<SafetyNetApi.AttestationResponse>() {
@Override
public void onComplete(@NonNull Task<SafetyNetApi.AttestationResponse> task) {
...
}
});
...
private byte[] getRequestNonce() {
String nonceData = "Safety Net Sample: " + System.currentTimeMillis();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
byte[] bytes = new byte[24];
mRandom.nextBytes(bytes);
try {
byteStream.write(bytes);
byteStream.write(nonceData.getBytes());
} catch (IOException e) {
return null;
}
return byteStream.toByteArray();
}
Logcat输出:
06-20 16:43:57.987 18222-18222/com.example.test W/System.err: com.google.android.gms.common.api.ApiException
06-20 16:43:57.987 18222-18222/com.example.test W/System.err: at com.google.android.gms.common.internal.zzb.zzx(Unknown Source)
06-20 16:43:57.987 18222-18222/com.example.test W/System.err: at com.google.android.gms.common.internal.zzbi.zzy(Unknown Source)
06-20 16:43:57.987 18222-18222/com.example.test W/System.err: at com.google.android.gms.common.internal.zzbj.zzo(Unknown Source)
06-20 16:43:57.987 18222-18222/com.example.test W/System.err: at com.google.android.gms.internal.zzbbd.zzb(Unknown Source)
06-20 16:43:57.987 18222-18222/com.example.test W/System.err: at com.google.android.gms.internal.zzbbd.setResult(Unknown Source)
06-20 16:43:57.988 18222-18222/com.example.test W/System.err: at com.google.android.gms.internal.zzcsh.zza(Unknown Source)
06-20 16:43:57.988 18222-18222/com.example.test W/System.err: at com.google.android.gms.internal.zzcrw.onTransact(Unknown Source)
06-20 16:43:57.988 18222-18222/com.example.test W/System.err: at android.os.Binder.execTransact(Binder.java:565)
我在这里缺少什么?