Necati Alp
Necati Alp

Reputation: 43

DevicePolicyManager.isDeviceOwnerApp Method Not Working Properly

I want to put my application in pinned screen mode. And I want a permission from user for this.

Permission Notice

But I don't always want to show this statement to user.

I found the setLockTaskPackages() method in the Android 5.0 Api document.

Android 5.0 Api's

private void provisionOwner() {
    DevicePolicyManager manager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName componentName = DeviceAdminSample.getComponentName(this);

    if(!manager.isAdminActive(componentName)) {
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
        startActivityForResult(intent, 0);
        return;
    }

    if (manager.isDeviceOwnerApp(getPackageName())) {
        manager.setLockTaskPackages(componentName, new String [] {getPackageName()});
        startLockTask();
    }
}

I also checked device owner list with this;

manager.getActiveAdmins()

and I see my package Id in admins list. Here is settings screen admin list My app(Teacher App) is device admin

But isDeviceOwnerApp(myPackageName) methods getting false

Why this method getting false and I can't pass the permission screen although My app is a device admin.

Upvotes: 4

Views: 2529

Answers (1)

Stanislav Bondar
Stanislav Bondar

Reputation: 6245

Device admin is not the same as device owner, there is many steps to achieve it. You can start research from official doc

Upvotes: 6

Related Questions