title: How to change password programmatically?
body: <p>I'm trying to create an android application that can change the password of the device. I read about <a href="http://developer.android.com/guide/topics/admin/device-admin.html#developing" rel="nofollow noreferrer">Device Administration Application</a> 
  I try to run <a href="https://stackoverflow.com/questions/9724428/how-can-i-set-up-screen-lock-with-a-password-programmatically">this sample</a> and this is my main activity code:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      final Activity context = this;
      final String new_pass = ((EditText)findViewById(R.id.editext)).getText().toString();
      ((Button)findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              DevicePolicyManager devicePolicyManager =
                      (DevicePolicyManager)context.getSystemService(context.DEVICE_POLICY_SERVICE);
              ComponentName demoDeviceAdmin = new ComponentName(context, MainActivity.class);
  
              devicePolicyManager.setPasswordQuality(
                      demoDeviceAdmin,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
              devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 5);
  
              boolean result = devicePolicyManager.resetPassword("123456",
                      DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
  
              Toast.makeText(context,
                      "button_lock_password_device..."+result,
                      Toast.LENGTH_LONG).show();
          }
      });
  }
  </code></pre>
  
  <p>and I got this error:</p>
  
  <pre><code>08-26 22:36:51.280  15249-15249/co.rishe.secretpolice.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
  java.lang.SecurityException: No active admin ComponentInfo{com.example.secretpolice.app/com.example.secretpolice.app.MainActivity}
          at android.os.Parcel.readException(Parcel.java:1425)
          at android.os.Parcel.readException(Parcel.java:1379)
          at android.app.admin.IDevicePolicyManager$Stub$Proxy.setPasswordQuality(IDevicePolicyManager.java:1359)
          at android.app.admin.DevicePolicyManager.setPasswordQuality(DevicePolicyManager.java:323)
          at co.rishe.secretpolice.app.MainActivity$1.onClick(MainActivity.java:32)
          at android.view.View.performClick(View.java:4211)
          at android.view.View$PerformClick.run(View.java:17267)
          at android.os.Handler.handleCallback(Handler.java:615)
          at android.os.Handler.dispatchMessage(Handler.java:92)
          at android.os.Looper.loop(Looper.java:137)
          at android.app.ActivityThread.main(ActivityThread.java:4898)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:511)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Can any one help me how can I fix it?</p>