12

我正在使用Android 5.0。該版本提供了SmartLock功能,該功能允許通過連接受信任的設備來解鎖密碼/模式。我有一個註冊爲可信設備的藍牙低功耗(BLE)設備。我想使用BLE解鎖(模式模式)手機。它將爲手機解鎖的BLE和手機連接時和數據可通過事件如何在我的應用程序中使用智能鎖定API來解鎖圖案模式?

if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) 
// Calling unlock by the SmartLock API 

如果有人用誰SMARTLOCK工作,請給我一些指導,以辦呢?我沒有找到任何SmartLock API來做到這一點。 enter image description here

+0

如果在您的智能鎖定設置中將BLE設備添加爲可信設備,則當您的手機與該BLE設備連接時,設備將自動解鎖。你正在尋找的東西仍然不清楚。請詳細說明這一點,並糾正我,如果我錯了任何地方。 –

+0

你說得對。但它有一個屏幕(滑動屏幕)。那個時候,我們必須滾動屏幕才能解鎖。我想忽略這一點。我認爲Smartlock有這個選項 – Jame

+0

你檢查過了嗎? HTTP://計算器。com/questions/30246425 /從屏幕接收服務/ 30365638#30365638 –

回答

-1

這可能有點複雜,但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(); 

您已經創建GoogleApiClientCredentialRequest對象之後,將它們傳遞到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); 
     // ... 
    } 
} 
+0

您以前使用過該功能嗎?我很困惑你的代碼API(使用密碼)和使用可信設備的smartlock – Jame

-1

我不認爲有SmartLock API。就像Pravin在評論中所說的那樣,智能鎖將在設備連接時自動禁用該模式。

我沒有試過,但一旦模式被禁止,你應該能夠(從this answer)下面繞過鎖屏:

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE); 
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); 
lock.disableKeyguard(); 

您將需要一個允許添加到您的清單:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> 
+0

我以前試過,但它無法解鎖智能鎖的滑動 – Jame

1

SmartLock沒有外部API。您可以查看Google Docs以供參考。

您可以檢查this樣品從GitHub上和here你會發現如何智能鎖API集成到應用的教程。

+0

如果我真的明白,你給我的智能鎖與我的問題中的智能鎖不同。我之前在鏈接中運行了智能鎖,但它僅適用於電子郵件,不適用於模式模式 – Jame

+0

@ user8430嗯,是的。本教程將爲您提供Smartlock的基本概念。像以前的答案一樣,您可以使用'KeyguardManager'來解鎖您的設備。 – AlphaQ

+0

我想你以前沒有嘗試過。請在回答 – Jame

相關問題