title: I cannot set device owner for my app on device
body: <p>I have been working on setting my apps to device owner through adb shell dpm command but the error came out</p>
  <pre><code> Error: Bad admin: ComponentInfo{com.example.oshao.autolock/com.example.oshao.
  </code></pre>
  <p>autolock.AdminReceiver}</p>
  <p>Here is my activity and manifests</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private DevicePolicyManager mDpm;
  private boolean isKioskModeEnabled = false;
  private Button btnEnabled;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      btnEnabled = (Button) findViewById(R.id.btnEnable);
      btnEnabled.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              enableKioskMode(!isKioskModeEnabled);
          }
      });
  
      ComponentName deviceAdmin = new ComponentName(this, AdminReceiver.class);
      mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
      if (!mDpm.isAdminActive(deviceAdmin)) {
          Toast.makeText(this, &quot;This ap is not a device admin&quot;, Toast.LENGTH_SHORT).show();
      }
  
      if (mDpm.isDeviceOwnerApp(getPackageName())) {
          mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
      } else {
          Toast.makeText(this, &quot;This app is not the device owner&quot;, Toast.LENGTH_SHORT).show();
      }
  }
  
  private void enableKioskMode(boolean enabled) {
  
      if (enabled) {
  
          if (mDpm.isLockTaskPermitted(this.getPackageName())) {
  
              startLockTask();
              isKioskModeEnabled = true;
              btnEnabled.setText(&quot;Exit Kiosk Mode&quot;);
  
          } else {
              Toast.makeText(this, &quot;Kiosk Mode is not permitted&quot;, Toast.LENGTH_SHORT).show();
          }
      } else {
  
          stopLockTask();
          isKioskModeEnabled = false;
          btnEnabled.setText(&quot;Enter Kiosk Mode&quot;);
  
      }
  
  }
  }
  </code></pre>
  <p>the manifest:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  </code></pre>
  <p></p>
  <pre><code>&lt;application
      android:allowBackup=&quot;true&quot;
      android:icon=&quot;@mipmap/ic_launcher&quot;
      android:label=&quot;@string/app_name&quot;
      android:supportsRtl=&quot;true&quot;
      android:theme=&quot;@style/AppTheme&quot;&gt;
  
  
      &lt;activity android:name=&quot;.MainActivity&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
              &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;receiver
          android:name=&quot;com.example.oshao.autolock.AdminReceiver&quot;
          android:permission=&quot;android.permission.BIND_DEVICE_ADMIN&quot;&gt;
  
          &lt;meta-data
              android:name=&quot;android.app.admin&quot;
              android:resource=&quot;@xml/device_admin&quot;/&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.app.action.DEVICE_ADMIN_ENABLED&quot; /&gt;
          &lt;/intent-filter&gt;
  
      &lt;/receiver&gt;
  
  &lt;/application&gt;
  </code></pre>
  
  <p>I am not sure why the error is still out there, is that because one device could only have single app that be set device owner?
  Another question is that the adb command could be implemented on a device without account and connect to pc in order to input command in terminal. Can I do it by code in app under the circumstances the device is not rooted because I have several devices and it is hard to set them one by one, Thanks</p>