title: Android Device Admin not working
body: <p>I am new in android and i would like to lock the phone. So I Read through Device Admin documentation. and have my code looking like this.  But it doesnt seem to notice it on my manifest suggests if i have it defined in it which i do</p>
  
  <p>my manifest.xml
      
      
      </p>
  
  <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
  &lt;activity android:name=".MainLauncher"android:label="@string/app_name"&gt;
  &lt;intent-filter&gt;
  &lt;action android:name="android.intent.action.MAIN" /&gt;
  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
  &lt;/intent-filter&gt;
  &lt;/activity&gt;
  &lt;activity android:name=".Controller"android:label="@string/app_name"&gt;
  &lt;/activity&gt; 
  
  &lt;activity android:name=".DeviceAdminSample$Controller"android:label="@string/activity_sample_device_admin"&gt;
  &lt;intent-filter&gt;
  &lt;action android:name="android.intent.action.MAIN" /&gt;
  &lt;category android:name="android.intent.category.SAMPLE_CODE" /&gt;
  &lt;/intent-filter&gt;
  
  &lt;/activity&gt;
  
  &lt;receiver android:name=".DeviceAdminSample"android:label="@string/sample_device_admin"android:description="@string/sample_device_admin_description"android:permission="android.permission.BIND_DEVICE_ADMIN"&gt;
  &lt;meta-data android:name="android.app.device_admin"android:resource="@xml/device_admin_sample" /&gt;
  &lt;intent-filter&gt;
  &lt;action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /&gt;
  &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  
  &lt;/application&gt;
  &lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD"/&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>My Code</p>
  
  <pre><code>public class DeviceAdminSample extends DeviceAdminReceiver {
  
  public static class Controller extends Activity {
              static final int RESULT_ENABLE = 1;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
          mAM = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
          mDeviceAdminSample = new ComponentName(Controller.this, DeviceAdminSample.class);
  
          mEnableButton = (Button)this.findViewById(R.id.button1);
          mEnableButton.setOnClickListener(new OnClickListener() {
  
              public void onClick(View v) {
                  Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                  intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                          mDeviceAdminSample);
                  intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                          "Additional text explaining why this needs to be added.");
                  startActivityForResult(intent, RESULT_ENABLE);
              }
          });
  
          mDisableButton = (Button)this.findViewById(R.id.button2);
          mDisableButton.setOnClickListener(new OnClickListener() {
  
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  mDPM.removeActiveAdmin(mDeviceAdminSample);
                  updateButtonStates();
              }
          });
  
          mForceLockButton = (Button)this.findViewById(R.id.button3);
          mForceLockButton.setOnClickListener(new OnClickListener() {
  
              public void onClick(View v) {
                  Log.i("                                                                                                            In","In the forc lock button");
                  if (mAM.isUserAMonkey()) {
                      AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
                      builder.setMessage("You can't lock my screen because you are a monkey!");
                      builder.setPositiveButton("I admit defeat", null);
                      builder.show();
                      return;
                  }
                  boolean active = mDPM.isAdminActive(mDeviceAdminSample);
                  if (active) {
                  v   mDPM.lockNow();
                  }
              }
          });
      }
      void updateButtonStates() {
          boolean active = mDPM.isAdminActive(mDeviceAdminSample);
          if (active) {
              mForceLockButton.setEnabled(true);
          } else {
              mForceLockButton.setEnabled(false);
          }
      }
  }
  }
  </code></pre>
  
  <p>My Other Activity</p>
  
  <pre><code>package com.examples;
  
  
  public class MainLauncher extends Activity {
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mainlauncher);
  
  Button btnLock = (Button)this.findViewById(R.id.button22);
  btnLock.setOnClickListener(new OnClickListener() {
  
      public void onClick(View v) {
          KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);  
          KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
  
          lock.reenableKeyguard();
  
      }
  });
  
  Button btnDevice = (Button)this.findViewById(R.id.button11);
  btnDevice.setOnClickListener(new OnClickListener() {
  
      public void onClick(View arg0) {
      try{                    
          Intent openScreen = new Intent();
          openScreen.setClass(MainLauncher.this, DeviceAdminSample.class);
          startActivity(openScreen);
      }
          catch(Exception e)
          {Log.i("DeviceAdmin button",String.valueOf(e));}
      }
  });
  }
  
  
  }
  </code></pre>