在Android N的文档中提到了预览:
此早期版本未经兼容性测试套件(CTS)批准。依赖于CTS批准的版本的应用程序将无法运行(例如Android Pay)。
在我的Android应用中,我想检查设备/版本是否在首次启动时获得CTS批准。这可能吗? Android Pay如何做到这一点?
答案 0 :(得分:3)
SafetyNet API允许您运行兼容性检查:
允许您的应用检查运行它的设备是否与通过Android兼容性测试的设备的配置文件相匹配。兼容性检查通过收集有关设备硬件和软件特征的信息(包括平台构建)来创建设备配置文件。
使用GoogleApiClient
连接SafetyNet.API
后,您可以致电
byte[] nonce = getRequestNonce(); // Should be at least 16 bytes in length.
SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
.setResultCallback(new ResultCallback<SafetyNetApi.AttestationResult>() {
@Override
public void onResult(SafetyNetApi.AttestationResult result) {
Status status = result.getStatus();
if (status.isSuccess()) {
// Indicates communication with the service was successful.
// result.getJwsResult() contains the result data
} else {
// An error occurred while communicating with the service
}
}
});
按照the instructions解析响应,在生成的JSON中查找"ctsProfileMatch": true
。