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);
Related
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...
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);
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
i am able to launch any apps which are on emulator screen from my app just with the help of their package names but after launching those apps if i press home button and if i launch the same app from my app it's being launched from initial state not where i used and left that before...for that i tried setting the FLAG_ACTIVITY_REORDER_TO_FRONT on the intent which is used to launch the app but there is no effect...
Here is my code
PackageManager packageManager = getPackageManager();
Intent intent=new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent=packageManager.getLaunchIntentForPackage("com.android.email");
startActivity(intent);
You don't get used of FLAG_ACTIVITY_REORDER_TO_FRONT, because you're rewriting the intent object. Fix your code to:
PackageManager packageManager = getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage("com.android.email");
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
Hope, this helps.