title: Android Device Administrator permission activity not launching
body: <p>I'm trying to enable my application as a device administrator. The code that attempts to call the activity which gives my app permission to be device administrator which is in the first activity of my app is as follows:</p>
  
  <pre><code>import android.app.Activity;
  import android.app.admin.DevicePolicyManager;
  import android.content.ComponentName;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  import com.google.android.gms.common.GooglePlayServicesUtil;
  
  public class RegisterActivity extends Activity {
      // alert dialog manager
      AlertDialogManager alert = new AlertDialogManager();
  
      // Internet detector
      ConnectionDetector cd;
  
      // UI elements
      EditText txtName;
      EditText txtEmail;
  
      // Register button
      Button btnRegister;
  
      static final int ACTIVATION_REQUEST = 47; //Request ID for Device Administrator
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_register);
          //Unrelated 
          int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
          if (status != 0) {
              Toast.makeText(this, "This device is not supported - please download Google Play Services.", 
                        Toast.LENGTH_LONG).show();
          }
  
          //Begin enabling device administrator 
          Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
          ComponentName deviceAdminComponentName = new ComponentName(this, DeviceAdmin.class);
          intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdminComponentName);  
          intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "You must enable device administration for certain features"
                  + " of the app to function.");  
  
          //I thought that this would start the activity that lets the user
          //choose whether to enable the app as a device admin
          startActivityForResult(intent, ACTIVATION_REQUEST);
  
  
  
          //Also contains code pertaining to unrelated Google Cloud messaging features
          //and an onClick() method, all inside of onCreate()
  
  
          }
  
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      switch (requestCode) {
          case ACTIVATION_REQUEST:
              if (resultCode == Activity.RESULT_OK) {
                  Log.i("DeviceAdminSample", "Administration enabled!");
              } 
              else {
                  Log.i("DeviceAdminSample", "Administration enable FAILED!");
              }
              return;
      }
      super.onActivityResult(requestCode, resultCode, data);
  }
  </code></pre>
  
  <p>Using this code, when I run my application the activity comes up, then has the animation in which it looks like it is opening a new activity, but then that animation stops and it remains on the current activity without prompting the user to enable device admin. None of my log messages pertaining to device admin are hit.  However, when looking at the current device adminsitrators on the Settings->Security->Device Administrators page, my app shows up but it is unchecked as a device admin.</p>
  
  <p>Here is the code for my DeviceAdmin subclass, though I can't see where the problem could be coming from in this code:</p>
  
  <pre><code>import android.app.admin.DeviceAdminReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.util.Log;
  
  public class DeviceAdmin extends DeviceAdminReceiver {
  
      @Override
      public void onEnabled(Context context, Intent intent) {
          super.onEnabled(context, intent);
          Log.i("Device Admin: ", "Enabled");
      }
  
      @Override
      public String onDisableRequested(Context context, Intent intent) {
          return "Admin disable requested";
      }
  
      @Override
      public void onDisabled(Context context, Intent intent) {
          super.onDisabled(context, intent);
          Log.i("Device Admin: ", "Disabled");
      }
  
      @Override
      public void onPasswordChanged(Context context, Intent intent) {
          super.onPasswordChanged(context, intent);
          Log.i("Device Admin: ", "Password changed");
      }
  
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>UPDATE: The Device Admin receiver in my Android Manifest is as follows:</p>
  
  <pre><code>    &lt;!-- Device Administration Receiver --&gt;
      &lt;receiver
          android:name="com.myPackage.DeviceAdminReceiver"
          android:permission="android.permission.BIND_DEVICE_ADMIN"&gt;
          &lt;meta-data android:name="android.app.device_admin"
                     android:resource="@xml/device_admin" /&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /&gt;
              &lt;action android:name="android.app.action.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED" /&gt;
              &lt;action android:name="android.app.action.ACTION_DEVICE_ADMIN_DISABLED" /&gt;
          &lt;/intent-filter&gt;           
      &lt;/receiver&gt;        
  </code></pre>