Issue in Hiding a application from another Application in Android - android

What i am trying to do is hiding a installed application from another application like this :
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName("com.example.activitypackgename","com.example.activitypackgename.LauncherActivity");
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
but it is throwing exception
java.lang.SecurityException: Permission Denial: attempt to change
component state
code works fine if trying to hide same application. I need to know is their any way to hide a app from another app.? Thanks in advance.

Related

android hide app icon programmatically just works in my packagename

This code works and hides my application icon:
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName("myPackageName", "MyLauncherClass");
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
But I need hide another application icon.
When i replace myPackageName and MyLauncherClass with another application package name and launcher class, app force closed.
This means that i can hide my app icon only?
This means that i can hide my app icon only?
Correct. There may be some options for doing this as a device owner app, but ordinary apps cannot disable other apps.

How to hide an app and give it the right to be access from another app?

I hope anyone can help me or give me a clear solution,
I have an app that I don't want to be opened directly from the user, so I need to hide its icon.
and in the other hand, I want to access this application from another app (App2), so I wrote this code in the function of onClick of a certain button of App2:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(package name of the first app );
startActivity(launchIntent);
Before hiding the App1 , everything was working perfectly No errors but after hiding it using the following code, it crashes:
PackageManager packageManager = this.getPackageManager();
ComponentName componentName = new ComponentName(this,FingerActivity.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
and the following error appear in Android Studio:
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.neurotec.samples.multibiometric/.fingers.FingerActivity }
Error type 3 Error: Activity class
{com.neurotec.samples.multibiometric/com.neurotec.samples.multibiometric.fingers.FingerActivity}
does not exist.
any idea?
any idea?
You disabled the component. You cannot start the component from any other app.
I have an app that I don't want to be opened directly from the user, so I need to hide its icon.
The simplest way for it to not have an icon is for you to not give it an icon. Change your <intent-filter> for that activity to be something custom for you, rather than having it have the MAIN/LAUNCHER values that causes home screens to put an icon for it in the launcher.

Hide installed app in android

i want to hide the installed app by another app in android application, lets say user has installed 3rd party app called Skype, Watsapp, facebook etc...
is there a way we can hide and show them upon click of a button from another app?. i tried below code. No luck, nothing happened to my launcher
PackageManager packageManager = context.getPackageManager();
ComponentName componentName = new ComponentName(context,
LauncherActivity.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
But here i was not getting how to hide a particular application?, i also followed these SO link
but i could not get to know how to hide a perticular application.
To hide/unhide an app, your app need to be the DevicePolicyManager. You can find more information about the device policy manager at http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html and you may need to use https://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#setApplicationHidden(android.content.ComponentName,%20java.lang.String,%20boolean)
DevicePolicyManager dpm =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName ownerComponent = new ComponentName(context, DeviceAdminReceiverImpl.class);
boolean newHiddenValue = true;
dpm.setApplicationHidden(ownerComponent, packageName, newHiddenValue);

Android how to programmatically hide launcher icon

my app is designed to only need to be run once. As such I want to hide the icon from the launcher after the first run, but without uninstalling the app.
I have seen similar applications - they can remove their own icons from the launcher app list. How can I achieve the same results? Thank you.
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Note that the icon may not be gone until the next reboot.
Hide app's icon using below code
PackageManager pkg=this.getPackageManager();
pkg.setComponentEnabledSetting(new ComponentName(this,SplashActivity.class),PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
// activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
Here is how to bring back the app's icon
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this,SplashActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
With Android Q (API 29) Google changed the Launcher icon visibility behaviour. Even if you disable your Launcher Activity or completely remove the
android.intent.category.LAUNCHER <intent-filter> from all your Activities, the app will appear in the launcher and open the Android OS app settings, with the exception of:
Packages that don't declare any permissions in their respective manifest files
System apps
Apps that don't contain any components inside their
respective manifest's tag
You can have an app without a launcher by NOT including an intent filter with MAIN and LAUNCHER in the declaration of the Activity in the AndroidManifest - the question then becomes how to do the first kick off.. Widget maybe ?
Hide app icon using this code:
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
and bring it back, with this:
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
NOTE: This will not work for Android 10

Cant hide application icon from the Android Menu?

I have also landed in a situation where I want to start Install of a third party app (lets say app Y) from my app (X) and I do not want application Y icon to get created on android main menu.
I have tried code below but still there is a icon of app Y that is getting created in main menu after App Y gets installed successfully. Just please remember that I can not change manifest of App Y as it is a third party app.
I have also tried suggestions on following link but they have not resolved my problem:
How to hide application icon from the Android Desktop?
++++++++++
File file = new File("/sdcard/MyApps/App Y.apk");
Intent intent = new Intent();
Uri uri = Uri.fromFile(file);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.removeCategory("android.intent.category.LAUNCHER");
intent.setDataAndType(Uri.parse(uri.toString()),
"application/vnd.android.package-archive");
startActivity(intent);
++++++++++
Please let me know your suggestions/inputs on this.
Thanks
The only way to do this is to remove the IntentFilter defined in the package's AndroidManifest.xml file: there is no way as a third party installer to do this.
In most cases the answer will be no you can't....
It depends of what kind of application "App Y" is. For e.g. if App Y is a library it is included in your app. There are some sample app's available on the Android site like; "Soft Keyboard"
http://developer.android.com/resources/samples/SoftKeyboard/index.html
Those are actually "services" which are not installed as applications. If App Y is a "normal" application it will be installed on it's own as this is Android's behaviour.
Kind regards and good luck on further development.
You're just modifying your intent. I don't think it's possible to accomplish what you're trying to accomplish. Why not let the user launch the other app themselves?
// Hide Application Icon
try{
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}catch (Exception e) {
e.printStackTrace();
}
// UnHide Application Icon
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName("com.example.removeicon","com.example.removeicon.LauncherActivity");
p.setComponentEnabledSetting(componentName , PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Yes you can hide your application icon but only on rooted devices or system signed apps.....the solution will be to first disable your application using shell command pm disable com.yourapppackagename and then enable it back using pm enable com.yourapppackagename this will first disable your app removing app icon from device and then enabling back your app will bring back the app icon only in device menu and not on homescreen.
if you do not want your app icon anywhere in device then just do not enable it back but then your app wont be of any use as its hidden now and cannot be used till you enable it back.
You can bluff just create an image with 0 opacity and smallest possible size then user will not be able to see the application.

Categories

Resources