Can I use packagemanager.setApplicationEnabledSetting() on non-rooted device in user app

2.6k Views Asked by At

I am trying to disable one of the app from my app. I have created a launcher app and trying to use following method of package manager

pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

But I'm getting SecurityException as SecurityException: Permission Denial: attempt to change component state from pid=20217, uid=10066, package uid=10067

Note: Somewhere I found the solution to this is to mention below permission in manifest

But I'm getting a warning in this permission that this permission is only granted to system apps.

1

There are 1 best solutions below

0
On

In order to disable/enable other apps your app must have system privileges. To achieve privileges you should do these steps.

Add this line to your manifest header android:sharedUserId="android.uid.system"

Add this permission to the manifest "android.permission.CHANGE_COMPONENT_ENABLED_STATE"

Sign your app with a system key.

I checked it in my launcher app.