【问题标题】:How to detect an CTS approved Android build?如何检测 CTS 批准的 Android 版本?
【发布时间】:2016-04-21 19:00:30
【问题描述】:

在Android N预览的文档中提到:

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

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

【问题讨论】:

标签: android android-pay cts


【解决方案1】:

SafetyNet API 允许您运行兼容性检查:

允许您的应用检查运行它的设备是否与已通过 Android 兼容性测试的设备的配置文件相匹配。兼容性检查通过收集有关设备硬件和软件特性(包括平台构建)的信息来创建设备配置文件。

一旦您使用SafetyNet.API 连接了GoogleApiClient,您就可以拨打电话

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

【讨论】:

  • 很好,如果 Google Play 服务不可用怎么办?
  • 只有 Google 有通过 CTS 的设备列表,所以如果没有 Google Play 服务连接到 Google 的服务器,就无法检查。
猜你喜欢
  • 1970-01-01
  • 2013-02-26
  • 2012-07-07
  • 2023-03-22
  • 2018-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多