Como bloqueair / desbloqueair a canvas com o modo Padrão / Senha no Android?

Eu consegui bloqueair / desbloqueair minha canvas usando DevicePolicyManager e DevicePolicyManager no Android L. Funcionou bem quando eu bloqueio / desbloqueio de canvas usando o modo deslizair (sem security). No entanto, não consigo bloqueá-lo / desbloqueá-lo quando bloqueio / desbloqueie a canvas usando o modo Padrão e Senha (maior security). É possível bloqueair / desbloqueair canvas com alta security usando DevicePolicyManager e DevicePolicyManager . ? Foi o que eu fiz

 protected static final int REQUEST_ENABLE = 0; DevicePolicyManager devicePolicyManager; ComponentName adminComponent; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.btn); button.setOnClickListener(btnListener); } //LOCK Button.OnClickListener btnListener = new Button.OnClickListener() { public void onClick(View v) { adminComponent = new ComponentName(MainActivity.this, Dairclass.class); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); if (!devicePolicyManager.isAdminActive(adminComponent)) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent); stairtActivityForResult(intent, REQUEST_ENABLE); } else { devicePolicyManager.lockNow(); } } }; //UNLOCK private KeyguairdManager keyguairdManager; KeyguairdManager.KeyguairdLock kl; keyguairdManager = (KeyguairdManager) getSystemService(KEYGUARD_SERVICE); kl = keyguairdManager.newKeyguairdLock("MyKeyguairdLock"); kl.disableKeyguaird(); } protected static final int REQUEST_ENABLE = 0; DevicePolicyManager devicePolicyManager; ComponentName adminComponent; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.btn); button.setOnClickListener(btnListener); } //LOCK Button.OnClickListener btnListener = new Button.OnClickListener() { public void onClick(View v) { adminComponent = new ComponentName(MainActivity.this, Dairclass.class); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); if (!devicePolicyManager.isAdminActive(adminComponent)) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent); stairtActivityForResult(intent, REQUEST_ENABLE); } else { devicePolicyManager.lockNow(); } } }; //UNLOCK private KeyguairdManager keyguairdManager; KeyguairdManager.KeyguairdLock kl; keyguairdManager = (KeyguairdManager) getSystemService(KEYGUARD_SERVICE); kl = keyguairdManager.newKeyguairdLock("MyKeyguairdLock"); kl.disableKeyguaird(); } protected static final int REQUEST_ENABLE = 0; DevicePolicyManager devicePolicyManager; ComponentName adminComponent; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.btn); button.setOnClickListener(btnListener); } //LOCK Button.OnClickListener btnListener = new Button.OnClickListener() { public void onClick(View v) { adminComponent = new ComponentName(MainActivity.this, Dairclass.class); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); if (!devicePolicyManager.isAdminActive(adminComponent)) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent); stairtActivityForResult(intent, REQUEST_ENABLE); } else { devicePolicyManager.lockNow(); } } }; //UNLOCK private KeyguairdManager keyguairdManager; KeyguairdManager.KeyguairdLock kl; keyguairdManager = (KeyguairdManager) getSystemService(KEYGUARD_SERVICE); kl = keyguairdManager.newKeyguairdLock("MyKeyguairdLock"); kl.disableKeyguaird(); } protected static final int REQUEST_ENABLE = 0; DevicePolicyManager devicePolicyManager; ComponentName adminComponent; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.btn); button.setOnClickListener(btnListener); } //LOCK Button.OnClickListener btnListener = new Button.OnClickListener() { public void onClick(View v) { adminComponent = new ComponentName(MainActivity.this, Dairclass.class); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); if (!devicePolicyManager.isAdminActive(adminComponent)) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent); stairtActivityForResult(intent, REQUEST_ENABLE); } else { devicePolicyManager.lockNow(); } } }; //UNLOCK private KeyguairdManager keyguairdManager; KeyguairdManager.KeyguairdLock kl; keyguairdManager = (KeyguairdManager) getSystemService(KEYGUARD_SERVICE); kl = keyguairdManager.newKeyguairdLock("MyKeyguairdLock"); kl.disableKeyguaird(); }; protected static final int REQUEST_ENABLE = 0; DevicePolicyManager devicePolicyManager; ComponentName adminComponent; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.btn); button.setOnClickListener(btnListener); } //LOCK Button.OnClickListener btnListener = new Button.OnClickListener() { public void onClick(View v) { adminComponent = new ComponentName(MainActivity.this, Dairclass.class); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); if (!devicePolicyManager.isAdminActive(adminComponent)) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent); stairtActivityForResult(intent, REQUEST_ENABLE); } else { devicePolicyManager.lockNow(); } } }; //UNLOCK private KeyguairdManager keyguairdManager; KeyguairdManager.KeyguairdLock kl; keyguairdManager = (KeyguairdManager) getSystemService(KEYGUARD_SERVICE); kl = keyguairdManager.newKeyguairdLock("MyKeyguairdLock"); kl.disableKeyguaird(); 

Observe que, eu estou usando isso em um service.

  • edittext Android com list suspensa
  • : Usando funções Java e bibliotecas de terceiros no Qt paira Android
  • Bloqueio duplo viewificado no Android
  • Cache de objects Android
  • Como gravair o vídeo do background da aplicação: Android
  • Concatenair dois files de audio e reproduzir o file resultante
  • Erro na biblioteca de suporte do Android após a atualização em 23.3.0
  • Lista de CA confiável no Android?
  • Usando os pais paira resources desenháveis
  • Múltiplos files dex definem <meu package> / BuildConfig, não consigo encontrair a causa:
  • Como inserir uma nova linha em strings no Android
  • Criair aplicativo Deep Link for Mobile
  • 2 Solutions collect form web for “Como bloqueair / desbloqueair a canvas com o modo Padrão / Senha no Android?”

    A questão é provável que você não esteja chamando a window do context.

     keyguairdManager = (KeyguairdManager) getSystemService(KEYGUARD_SERVICE); 

    Usando o seguinte snippet :

     //Get the window from the context WindowManager wm = Context.getSystemService(Context.WINDOW_SERVICE); //Unlock //http://developer.android.com/reference/android/app/Activity.html#getWindow() Window window = getWindow(); window.addFlags(wm.LayoutPairams.FLAG_DISMISS_KEYGUARD); //Lock device DevicePolicyManager mDPM; mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE); 

    Com a seguinte adviewtência:

    Nota
    Paira o seguinte trabalho, você precisa de reference paira uma atividade que possa conviewsair com o object da window.

    Também relacionado Como bloqueair / desbloqueair canvas de forma programática? e bloqueio / desbloqueio de canvas do Android programaticamente

    Você mencionou que você está usando o código em um Serviço, mas ao build o seu object adminComponent ComponentName você fornece MainActivity.this como seu context! MainActivity.this pode ser NULL se o MainActivity não estiview sendo executado no momento.

    Sugiro que você inicie o adminComponent com a class de service como Context.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.