I want to hide any application (Telegram, Viber, ...) from my app Android. I want to hide another apps in list installed apps from my app. I try with this code. I getting app package name and its activity name using this code by Praful Bhatnagar:
private void hideapplication() {
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));
TextView textview= (TextView)findViewById(R.id.textview);
ImageView imageview =(ImageView)findViewById(R.id.imageview);
for (ResolveInfo temp: appList) {
Log.v("my logs", "package and activity name = " + temp.activityInfo.packageName + " " + temp.activityInfo.name);
}
}
Use this package name & activity name in below code:
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.isChecked()) {
Toast.makeText(context, "Checked", Toast.LENGTH_SHORT).show();
ComponentName componentName = new ComponentName(applicationInfo.packageName, applicationInfo.name);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
}
});
But I am getting force close. How can I solve this problem? Can you help me?