-1

在 Android N preview 的文档中提到:

此早期版本未经兼容性测试套件 (CTS) 批准。依赖于 CTS 批准构建的应用程序将无法运行(例如 Android Pay)。

在我的 Android 应用程序中,我想检查设备/构建是否在首次启动时获得 CTS 批准。这可能吗?Android Pay 是如何做到的?

4

1 回答 1

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
    }
  }
});

并按照说明"ctsProfileMatch": true解析响应,在生成的 JSON 中查找。

于 2016-04-21T19:13:58.447 回答