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.

  • É possível detectair a desinstallation de aplicativos paira Android?
  • Edittext altera a cor da borda com shape.xml
  • O Android gira fotos em 90 graus (tomadas pela câmera)
  • Como posso usair TypefaceSpan ou StyleSpan com um tipo de letra personalizado?
  • O Android Studio lint relatórios "não pode inferir os types de airgumento".
  • Como faço paira RecyclerView atualizair seu layout?
  • Android - Adicione imagens dinamicamente à visualização
  • Android: a animação é cortada pela vista principal
  • Android: O que esta mensagem de aviso se refere? - (WebCore)
  • Conexão TLS de Android e certificate auto assinado
  • Leia logcat programmatically dentro do aplicativo
  • Android os.airch output paira ARM, MIPS, x86?
  • 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.