2015-11-03 106 views
0

我想創建一個自定義android屏幕解鎖選項(基本上是覆蓋默認解鎖屏幕,並覆蓋幻燈片解鎖按鈕)。在解鎖時,它應指向鍵盤以輸入密碼,並以默認方式運行。 我試圖創建這個小部件,但無法找到一種方法來添加這個像解鎖屏幕。任何幫助將不勝感激。我正在使用android studio。創建自定義屏幕和按鍵解鎖android

+0

關於這個問題已經有很多了...請看看[link1](http://stackoverflow.com/questions/20943407/create-an-android-lock-screen),[link2 ](http://stackoverflow.com/questions/10864300/create-a-lock-screen-of-my-own),[link3](http://stackoverflow.com/questions/21983462/creating-custom-lockscreen -in-機器人),... – Marko

回答

1

這是一個很好的例子,你在找什麼。 https://github.com/googlesamples/android-ConfirmCredential

private void showAuthenticationScreen() { 
    // Create the Confirm Credentials screen. You can customize the title and description. Or 
    // we will provide a generic one for you if you leave it null 
    Intent intent = mKeyguardManager.createConfirmDeviceCredentialIntent(null, null); 
    if (intent != null) { 
     startActivityForResult(intent, REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS); 
    } 
} 

這是對結果和獲得認證的開放意圖的小碼。但我會建議嘗試下載代碼並看看它。

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) { 
     // Challenge completed, proceed with using cipher 
     if (resultCode == RESULT_OK) { 
      if (tryEncrypt()) { 
       showPurchaseConfirmation(); 
      } 
     } else { 
      // The user canceled or didn’t complete the lock screen 
      // operation. Go to error/cancellation flow. 
     } 
    } 
}