這可能有點複雜,但Google已經提供了關於此用法的巨大Docs。
要請求存儲的憑證,您必須創建一個配置爲訪問憑證API的GoogleApiClient
實例。
mCredentialsApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.enableAutoManage(this, this)
.addApi(Auth.CREDENTIALS_API)
.build();
一個CredentialRequest對象指定要從請求憑據登錄系統。使用基於密碼的登錄的setPasswordLoginSupported
方法和用於聯合登錄服務的setAccountTypes()
方法(如Google登錄)構建CredentialRequest
。
mCredentialRequest = new CredentialRequest.Builder()
.setPasswordLoginSupported(true)
.setAccountTypes(IdentityProviders.GOOGLE, IdentityProviders.TWITTER)
.build();
您已經創建GoogleApiClient
和CredentialRequest
對象之後,將它們傳遞到CredentialsApi.request()
方法來請求保存您的應用程序憑據。
Auth.CredentialsApi.request(mCredentialsClient, mCredentialRequest).setResultCallback(
new ResultCallback<CredentialRequestResult>() {
@Override
public void onResult(CredentialRequestResult credentialRequestResult) {
if (credentialRequestResult.getStatus().isSuccess()) {
// See "Handle successful credential requests"
onCredentialRetrieved(credentialRequestResult.getCredential());
} else {
// See "Handle unsuccessful and incomplete credential requests"
resolveResult(credentialRequestResult.getStatus());
}
}
});
在一個成功的證書請求,請使用所產生的Credential對象來完成用戶的登錄到您的應用程序。使用getAccountType()
方法確定檢索到的憑據的類型,然後完成適當的登錄過程。
private void onCredentialRetrieved(Credential credential) {
String accountType = credential.getAccountType();
if (accountType == null) {
// Sign the user in with information from the Credential.
signInWithPassword(credential.getId(), credential.getPassword());
} else if (accountType.equals(IdentityProviders.GOOGLE)) {
// The user has previously signed in with Google Sign-In. Silently
// sign in the user with the same ID.
// See https://developers.google.com/identity/sign-in/android/
GoogleSignInOptions gso =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.setAccountName(credential.getId())
.build();
OptionalPendingResult<GoogleSignInResult> opr =
Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
// ...
}
}
如果在您的智能鎖定設置中將BLE設備添加爲可信設備,則當您的手機與該BLE設備連接時,設備將自動解鎖。你正在尋找的東西仍然不清楚。請詳細說明這一點,並糾正我,如果我錯了任何地方。 –
你說得對。但它有一個屏幕(滑動屏幕)。那個時候,我們必須滾動屏幕才能解鎖。我想忽略這一點。我認爲Smartlock有這個選項 – Jame
你檢查過了嗎? HTTP://計算器。com/questions/30246425 /從屏幕接收服務/ 30365638#30365638 –