I want to hide any application(whatsapp, facebook...) from my app. I try with my own app hide/unhide from list. Its work perfectly. But I want to hide another app from my app. I try with this code.
I getting app package name & its activity name using this code.
public void getPackageAndActivityname() {
final PackageManager pm = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List < ResolveInfo > appList = pm.queryIntentActivities(mainIntent, 0);
Collections.sort(appList, new ResolveInfo.DisplayNameComparator(pm));
for (ResolveInfo temp: appList) {
Log.e("HIDEAPP", "package:- " + temp.activityInfo.packageName + " activity name:- " + temp.activityInfo.name);
}
}
Use this package name & activity name in below method(eg. hide UC Brower).
public void hideApp() {
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName("com.UCMobile.intl", "com.uc.browser.UCMobileApp"); // ucWebbrowser hide from app list
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
And my manifest file put this permission.
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>
But i am getting this type of error
java.lang.SecurityException: Permission Denial: attempt to change component state from pid=26587, uid=10477, package uid=10426
I refer this two links. Link 1 And Link 2. But I am getting this type of error.I run this app in Motorola Moto G phone(OS: Kitkat 4.4.4). How can I solve this problem?