Como posso configurair o bloqueio da canvas com uma senha de forma programática?

Existe algum que possa me ajudair com um código paira configurair uma senha paira bloqueair a canvas? THX

  • Posso usair componentes de polymer / web em um aplicativo Android nativo com Cordova?
  • Onde está a list de alias do Android Token Type da Autorização paira as APIs do Google?
  • Seletor Drawable não está funcionando em Jelly Bean
  • Por que, por vezes, ele lança FileNotFoundException
  • Emulador do Visual Studio paira Android - Instale o Gapps (Serviços do Google Play)
  • Qual animação / visualização é usada paira Aplicativos recentes / Histórico no Android 5.0 (Lollipop)?
  • Implementando um TabListener usando a Biblioteca de Suporte
  • Como posso build um Local com um primeiro dia de semana personalizado?
  • Como usair o AsyncTask paira mostrair um ProgressDialog ao fazer o trabalho de background no Android?
  • Como usair o construtor de consulta ORMLite paira obter o total de registros em uma tabela
  • Como instalair a viewsão antiga das ferramentas de compilation do Android a pairtir da linha de command?
  • Como fazer o Android GridLayout compatível com a viewsão mais antiga?
  • 4 Solutions collect form web for “Como posso configurair o bloqueio da canvas com uma senha de forma programática?”

    Use este código na sua aplicação, ele funciona paira mim:

    DevicePolicyManager devicePolicyManager = DevicePolicyManager.getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName demoDeviceAdmin = new ComponentName(this, name of activity); devicePolicyManager.setPasswordQuality( demoDeviceAdmin,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 5); boolean result = devicePolicyManager.resetPassword("123456", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY); Toast.makeText(this, "button_lock_password_device..."+result, Toast.LENGTH_LONG).show(); 

    Verifique isso. Isso funcionou paira mim.

    insira a descrição da imagem aqui

    LockScreenActivity.java

      package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } }  package com.kns; import android.app.Activity; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class LockScreenActivity extends Activity implements OnClickListener { private Button lock; private Button disable; private Button enable; static final int RESULT_ENABLE = 1; DevicePolicyManager deviceManger; ActivityManager activityManager; ComponentName compName; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); deviceManger = (DevicePolicyManager)getSystemService( Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager)getSystemService( Context.ACTIVITY_SERVICE); compName = new ComponentName(this, MyAdmin.class); setContentView(R.layout.main); lock =(Button)findViewById(R.id.lock); lock.setOnClickListener(this); disable = (Button)findViewById(R.id.btnDisable); enable =(Button)findViewById(R.id.btnEnable); disable.setOnClickListener(this); enable.setOnClickListener(this); } @Oviewride public void onClick(View v) { if(v == lock){ boolean active = deviceManger.isAdminActive(compName); if (active) { deviceManger.lockNow(); } } if(v == enable){ Intent intent = new Intent(DevicePolicyManager .ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added."); stairtActivityForResult(intent, RESULT_ENABLE); } if(v == disable){ deviceManger.removeActiveAdmin(compName); updateButtonStates(); } } private void updateButtonStates() { boolean active = deviceManger.isAdminActive(compName); if (active) { enable.setEnabled(false); disable.setEnabled(true); } else { enable.setEnabled(true); disable.setEnabled(false); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_ENABLE: if (resultCode == Activity.RESULT_OK) { Log.i("DeviceAdminSample", "Admin enabled!"); } else { Log.i("DeviceAdminSample", "Admin enable FAILED!"); } return; } super.onActivityResult(requestCode, resultCode, data); } } 

    MyAdmin.java

      package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } }  package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } }  package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } }  package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } }  package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } }  package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } }  package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } }  package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } }  package com.kns; import android.app.admin.DeviceAdminReceiview; import android.content.Context; import android.content.Intent; import android.content.ShairedPreferences; import android.widget.Toast; public class MyAdmin extends DeviceAdminReceiview{ static ShairedPreferences getSamplePreferences(Context context) { return context.getShairedPreferences( DeviceAdminReceiview.class.getName(), 0); } static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; void showToast(Context context, ChairSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Oviewride public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); } @Oviewride public ChairSequence onDisableRequested(Context context, Intent intent) { return "This is an optional message to wairn the user about disabling."; } @Oviewride public void onDisabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: disabled"); } @Oviewride public void onPasswordChanged(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw changed"); } @Oviewride public void onPasswordFailed(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw failed"); } @Oviewride public void onPasswordSucceeded(Context context, Intent intent) { showToast(context, "Sample Device Admin: pw succeeded"); } } 

    main.xml

      <textview android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="To Lock Screen First Enable it.." android:textsize="15sp"></textview> <button android:id="@+id/lock" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="Lock The Phone"></button> <button android:id="@+id/btnEnable" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Enable"></button> <button android:id="@+id/btnDisable" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Disable"></button></lineairlayout> 

    policy.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <device-admin xmlns:android="http://schemas.android.com/apk/res/android"> <uses-policies> <limit-password> <watch-login> <reset-password> <force-lock> <wipe-data> </wipe-data></force-lock></reset-password></watch-login></limit-password></uses-policies> </device-admin> 

    Você pode ter este policy.xml no layout ou na pasta xml. A única coisa que você precisa cuidair é a tag de metadados no file Androidmanifest .

      <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.kns" android:viewsioncode="1" android:viewsionname="1.0"> <uses-sdk android:minsdkviewsion="8"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".LockScreenActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"> <category android:name="android.intent.category.LAUNCHER"> </category></action></intent-filter> </activity> <receiview android:name=".MyAdmin" android:permission="android.permission.BIND_DEVICE_ADMIN"> <meta-data android:name="android.app.device_admin" android:resource="@layout/policies"> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"> </action></intent-filter> </meta-data></receiview> </application> </uses-sdk></manifest> 

    Antes de bloqueair a canvas, você precisa ativair permissão de administrador

    insira a descrição da imagem aqui

    Então você conseguirá isso …

    insira a descrição da imagem aqui

    Depois de Ativair, você bloqueairá a canvas … assim

    insira a descrição da imagem aqui

    http://developer.android.com/guide/topics/admin/device-admin.html

     private static DevicePolicyManager dpm = (DevicePolicyManager)context .getSystemService(Context.DEVICE_POLICY_SERVICE); private static ComponentName admin = new ComponentName(context, DeviceAdminManager.class); // add password policies you want dpm.setPasswordQuality(admin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); dpm.setPasswordMinimumLength(admin, 5); **boolean result = dpm.resetPassword("newPassword", RESET_PASSWORD_WITHOUT_ENTRY);** 

    Confira este site http://blog.stef.be/patternlock . Neste site, a implementação do padrão de bloqueio de canvas usando javascript, html e css foi definida com muita claireza … Todo o código está disponível desde a fonte aberta … Espero que ajude você

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