2017-07-04 8 views
0
I'm able to change the password,pin or Pattern from the below code, on Click function of Switch. 



switchPreferenceAppLock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { 
        @Override 
        public boolean onPreferenceChange(Preference preference, Object newValue) { 
         if (!((Boolean) newValue)) { 

         } else { 
          Log.d("Test", "Change to Phone Default Lock"); 

          Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD); 
         startActivity(intent); 
         return true; 
        } 
       }); 
      } 

私の目的は、アプリ内でユーザーの携帯電話セキュリティ係数(パターン、ピン、パスワードなど)を使用することです。私のアプリのユーザーが重要な機能を実行したい場合、セキュリティ画面が表示され、認証を求められ、認証後にユーザーにその機能を実行させるようにします。DevicePolicyManagerの設定画面でアンドロイドアプリのロック画面を開く

パスワードを変更するためにのみ使用されていますが、変更する代わりに電話機をロックするように設定する必要があります。Intent DevicePolicyManager.ACTION_SET_NEW_PASSWORDはパスワードの変更にのみ使用されます。私のAppの同じ設定画面。

答えて

2

API21+では、KeyguardManager.createConfirmDeviceCredentialIntent(...)を使用して新しいIntentを作成することができます。これにより、ユーザーは身元確認のためのロック画面に移動し、startActivityForResult(...)で開始できます。ここでは、ロック画面の意図を起動するための迅速なサンプルだ:

KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE) 
boolean isSecure = keyguardManager.isKeyguardSecure(); 

if (isSecure) { 
    Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(null, null); 
    startActivityForResult(intent, YOUR_REQUEST_CODE); 
} else { 
    // no lock screen set, show the new lock needed screen 
} 

その後、あなたは結果をチェック:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    switch (requestCode) { 
     case YOUR_REQUEST_CODE: 
      if (resultCode == RESULT_OK) { 
       // user authenticated 
      } else { 
       // user did not authenticate 
      } 
      break; 
     default: 
      super.onActivityResult(requestCode, resultCode, data); 
    } 
} 
関連する問題