在Android中ñ預覽的文件中提到:如何檢測CTS批准的Android版本?
這個早期版本是不認可的兼容性測試套件(CTS)。依賴CTS批准構建的應用程序將無法工作(例如Android Pay)。
在我的Android應用程序中,我想檢查設備/版本是否在首次啓動時獲得CTS批准。這可能嗎? Android Pay如何做到這一點?
在Android中ñ預覽的文件中提到:如何檢測CTS批准的Android版本?
這個早期版本是不認可的兼容性測試套件(CTS)。依賴CTS批准構建的應用程序將無法工作(例如Android Pay)。
在我的Android應用程序中,我想檢查設備/版本是否在首次啓動時獲得CTS批准。這可能嗎? Android Pay如何做到這一點?
的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服務不可用,該怎麼辦? – friedger
只有Google擁有通過CTS的設備列表,因此如果沒有Google Play服務與Google服務器的連接,則無法檢查。 – ianhanniballake
鏈接到文檔:http://developer.android.com/preview/support.html#general(可能已經過時了) – friedger