title: Why does android device administration not work properly
body: <p>I am setting two buttons on the screen. Whenever I press the first button it will disable the camera. ( as an admin ) </p>
  
  <p>I have set manifest ;</p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.example.firstapplication.MainActivity"
          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;!-- This is where we register our receiver --&gt;
      &lt;receiver
          android:name=".DemoDeviceAdminReceiver"
          android:permission="android.permission.BIND_DEVICE_ADMIN" &gt;
          &lt;intent-filter&gt;
  
              &lt;!-- This action is required --&gt;
              &lt;action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /&gt;
          &lt;/intent-filter&gt;
  
          &lt;!-- This is required this receiver to become device admin component. --&gt;
          &lt;meta-data
              android:name="android.app.device_admin"
              android:resource="@xml/device_admin_sample" /&gt;
      &lt;/receiver&gt;
  
  
  &lt;/application&gt;
  </code></pre>
  
  <p>I have wrote code as ;</p>
  
  <pre><code>public class MainActivity extends Activity  {
  
  static final int ACTIVATION_REQUEST = 47; // identifies our request id
  DevicePolicyManager devicePolicyManager;
  ComponentName demoDeviceAdmin;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // ...
  
      // Initialize Device Policy Manager service and our receiver class
      devicePolicyManager = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
      demoDeviceAdmin = new ComponentName(this, DemoDeviceAdminReceiver.class);
  }
  
  /* begin, camera management block */
  static boolean click = false ;
  private OnClickListener setCamera = new OnClickListener() {
      public void onClick(View v) {
        if ( click == false ) {
            startCamera();
            click = true ;
        }
        else {
            stopCamera();
            click = false ;
        }
        activate () ; // activate device policy manager
      }
  };
  private void startCamera(){
          if(getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){ 
              camera.unlock();    
          } else {
                   ;
          }
      }
  
  @SuppressLint("NewApi") private void stopCamera(){
      devicePolicyManager. setCameraDisabled(demoDeviceAdmin, true);
  }
  
  /* end, camera management block */
  private OnClickListener closeApplication = new OnClickListener() {
      public void onClick(View v) {
       finish ();
      }
  };
  void initializeDPM ( ) {
      if (!devicePolicyManager.isAdminActive(demoDeviceAdmin)) {
  
              Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
              intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                      demoDeviceAdmin);
              intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
              "Additional text explaining why this needs to be added.");
              startActivityForResult(intent, ACTIVATION_REQUEST);
      } else {
              devicePolicyManager.lockNow();
      }
  }
  
  public void activate ( ) {
          // Activate device administration
          Intent intent = new Intent(
          DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
          intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
          demoDeviceAdmin);
          intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
          "told me to do this");
          startActivityForResult(intent, ACTIVATION_REQUEST);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      switch (requestCode) {
          case ACTIVATION_REQUEST:
              if (resultCode == Activity.RESULT_OK) {
                  // Has become the device administrator.
              } else {
                  //Canceled or failed.
              }
              return;
      }
      super.onActivityResult(requestCode, resultCode, data);
  }
  
  }
  </code></pre>
  
  <p>My admin class </p>
  
  <pre><code>public class DemoDeviceAdminReceiver extends DeviceAdminReceiver{
  @Override
  public void onEnabled(Context context, Intent intent) {
      super.onEnabled(context, intent);
  
  }
  
  
  @Override
  public void onDisabled(Context context, Intent intent) {
      super.onDisabled(context, intent);
      }
  }
  </code></pre>
  
  <p>my device_admin_sample  is;</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" &gt;
  
  &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;expire-password /&gt;
      &lt;encrypted-storage /&gt;
      &lt;disable-camera /&gt;
  &lt;/uses-policies&gt;
  &lt;/device-admin&gt;
  
  
  &lt;/LinearLayout&gt; 
  </code></pre>
  
  <p>Why I could not  close the camera as an admin ? </p>