title: Lock an Android Phone
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4545079/lock-the-android-device-programatically">Lock the android device programatically</a>  </p>
  </blockquote>
  
  
  
  <p>I want to be able to lock the Android phone with a password when I run a method.
  Does anyone have a reference or sample code for me to refer. Thanks</p>
  
  <p><strong>EDIT</strong>
  I have tried using </p>
  
  <pre><code>KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); 
  KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD_SERVICE); 
  lock.reenableKeyguard();
  </code></pre>
  
  <p>as said by the answer below, but I'm still trying to get it to add a password that I have specifically entered into the database at my server side, so the only way to unlock his phone is to enter the password that i set</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><a href="http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html</a></p>
  
  <p>been trying to work on it ^</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have seen that</p>
  
  <pre><code>device_admin_sample.xml
  </code></pre>
  
  <p>with the contents</p>
  
  <pre><code>&lt;device-admin xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    &lt;uses-policies&gt;
      &lt;limit-password /&gt;
      &lt;watch-login /&gt;
      &lt;reset-password /&gt;
      &lt;force-lock /&gt;
      &lt;wipe-data /&gt;
    &lt;/uses-policies&gt;
  &lt;/device-admin&gt;
  </code></pre>
  
  <p>But where do I put this xml file at.. it seems to have an error wherever i put</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Now, I have implemented it halfway and put this on hold upon seeing the comment below that I cannot lock the phone with a password. 
  But seeing the API documentation, there's a function to reset password with a new password.</p>
  
  <pre><code>resetPassword(String password, int flags)
  </code></pre>
  
  <p>So what is it? Can I implement password lock on the phone? or is the idea of locking the phone until a new password given by the server is entered, unable to be done? </p>