How to visible/invisible launcher icon in android? - android

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

Related

How to hide inside app icon on android marshmallow?

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);

How to hide all the app icons installed in android except setting and my installed app icon

I'm trying to make an app which would have this function that when i install this app only on tablet device then all the apps icon installed before my app on that tablet got hide. the main screen should look like that only my app icon and setting icon is shown on screen.
I used the following code but it only hiding my app icon not others. Can I do this or not ? if I can then help me for this. here is the code
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName
(this, com.example.junaidsaif.skyhighreward.MainScreen.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);
please help me for this

How to hide/unhide other applications icon?

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...

android hide app icon and make it visible

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);

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

Categories

Resources