I am developing a small application i.e AppHider
In this i get the list of user installed applications and their launcher name also by getting their package name
Now i want to hide/unhide the application, I used this code below but it is not working, so can anyone tell please, how can I hide/unhide the application icon of other apps
for hiding app icon
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(SingleAppActivity.this, applauncher); // 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);
for unhidding app icon
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(SingleAppActivity.this, applauncher);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
you have to add package name instead of classname.this see below code
Replace your
ComponentName componentName = new ComponentName(SingleAppActivity.this, applauncher);
with
ComponentName componentName = new ComponentName("apppackagename","apppackagename.launcher classname");
Thats it...
Related
I use marshmallow android.
I want inside app. Camera,Setting,internet... hide icon.
I know how to hide icon on kitkat android.
but I don't know how to hide icon on marshmallow.
how to hide app icon on android marshmallow?
use below code along with Package manager permission
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);
I want to allow the users of my Android app to hide/unhide it when they want.
I already have the code to perform the hide/unhide actions, and the hiding works fine.
But now how can I call the unhide method to let the app back?
I mean, if the app is hidden, where can the user, let's say, "click a button" that calls the method to make the app unhide?
Here is my hide/unhide code:
// method to hide the app icon
public static void hideAppIcon(final Context context)
{
PackageManager p = context.getPackageManager();
// activity which is first time open in manifest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
ComponentName componentName = new ComponentName(context, SplashActivity.class);
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
// method to unhide the app icon
public static void unhideAppIcon(final Context context)
{
PackageManager p = context.getPackageManager();
// activity which is first time open in manifest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
ComponentName componentName = new ComponentName(context, SplashActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
Here's a way I've learned from another app. Not "hiding" the icon, instead, change the icon and label of your app. Disguise the app as some built-in apps like "Settings" or "Calculator".
Another solution (which might be closer to your need) is to add an intent-filter in your app, detecting something like phone calls. If users call a certain number, you unhide your app.
see this for more infomation.
Hope this will help.
I'm working on my app. there's two app, one should be hide. and open by another one. I try code like this in app A
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
and try to open app A by code
Intent intent = MainActivity.this.getPackageManager()
.getLaunchIntentForPackage("com.example.hideicon");
startActivity(intent);
but it didn't work.
For hide app icon
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(Test.this,com.example.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
For display app icon
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(Test.this, com.example.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
It will not work since you have disabled the component and haven't enabled it before starting. To disable/enable it requires the permission.
please check this link i hope its useful to you.
reference link
remove launcher in manifest file from main acitivity.and programatically set it.
I solve my question . firstly you must hide your app icon by remove
<category android:name="android.intent.category.LAUNCHER"
second you can add code in app B
Intent intent = new Intent("com.example.hideicon");
intent.setComponent(ComponentName
.unflattenFromString("com.example.hideicon/com.example.hideicon.MainActivity"));
intent.addCategory("android.intent.category.LAUNCHER");
startActivity(intent);
I am creating an application in which i need to hide icon launcher and show icon launcher on request. I used below code to hide launcher icon.
<category android:name="android.intent.category.LAUNCHER" /> // Remove this line from manifest.xml
or
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
By using these snippet of code, I am only able to hide application icon.
In order to show i used these code snippet
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
and
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
But none of them is effecting or i am not able to retrieve launcher icon back programmatically. Please suggest me how can i achieve this task.
Thanks in advance
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