startLockTask() without request user action
<p>I want to activate startLockTask() without any request for users. So at first i read this <a href="https://developer.android.com/guide/topics/admin/device-admin.html" rel="nofollow">Device Administration</a>
and create small sample application. In result i have my application in device administrators list but when i call startLockTask() it still execute not in silent mode.
When i'm trying to call it so:</p>

<pre><code>    DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    String[] packages = {this.getPackageName()};                        
    myDevicePolicyManager.setLockTaskPackages(deviceAdminComponentName, packages);
    startLockTask();
</code></pre>

<p>i'm getting next exception :<code>java.lang.SecurityException: Admin ComponentInfo{com.hssoft.deviceadmintest/com.hssoft.deviceadmintest.DeviceAdmin} does not own the device</code></p>

<p>So i have Device administrator but i'm not device owner. What i'm doing wrong, can somebody help?
Here is my full app code:</p>

<p>Manifest file:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hssoft.deviceadmintest"&gt;

    &lt;application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"&gt;
        &lt;activity android:name=".MainActivity"&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;receiver
            android:name="com.hssoft.deviceadmintest.DeviceAdmin"
            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.PROFILE_PROVISIONING_COMPLETE"/&gt;
            &lt;/intent-filter&gt;
        &lt;/receiver&gt;
    &lt;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p>xml/device_admin.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;device-admin&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;
</code></pre>

<p>DeviceAdmin.java:</p>

<pre><code>package com.hssoft.deviceadmintest;

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>MainActivity.java:</p>

<pre><code>package com.hssoft.deviceadmintest;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    static final int ACTIVATION_REQUEST = 1;
    ComponentName deviceAdminComponentName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        deviceAdminComponentName = new ComponentName(this, DeviceAdmin.class);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdminComponentName);

        startActivityForResult(intent, ACTIVATION_REQUEST);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case ACTIVATION_REQUEST:
                if (resultCode == Activity.RESULT_OK) {
                    Log.i("MainActivity", "Administration enabled!");

                    DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
                    String mPackageName = this.getPackageName();
                    if (myDevicePolicyManager.isDeviceOwnerApp(mPackageName)) {
                        myDevicePolicyManager.setLockTaskPackages(deviceAdminComponentName, new String[]{mPackageName});
                    }

                    if (myDevicePolicyManager.isLockTaskPermitted(mPackageName)) {
                        startLockTask();
                    }
                } else {
                    Log.i("MainActivity", "Administration enable FAILED!");
                }

                return;
        }

        super.onActivityResult(requestCode, resultCode, data);
    }
}
</code></pre>