Cant hide application icon from the Android Menu? - android

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.

Related

Resetting default launcher to system factory default

I ran into the following issue: I have an app I want my user to be able to select it as the launcher app. So far, no issues there.
Clearing said selection programmatically also isnt an issue here. Where my issue occurs is the following:
When I my custom launcher programmatically I want to go back to default launcher app, e.g. the default on a samsung galaxy. clearing the launch settings over clearPackagePrefferedActivities clears all of it but once i press the home button I get the dialog to select a default launcher again.
Is there anyway to revert back programmatically to the default launcher?
The user always needs to confirm a change in the default settings. You can always trigger the "default launcher" dialog by
PackageManager pm = getPackageManager();
ComponentName cm = new ComponentName(this, FakeLauncherActivity.class);
pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent homeIntent= new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Where FakeLauncherActivity is just another Activity in your app with the intent-filter HOME/MAIN/DEFAULT (without LAUNCHER).
If you want to know the default system launcher you could query the intents answering the LAUNCHER Intent, but if the user has another Launcher installed, you will not know which one is the default system launcher.
Even if this is not a complete solution for your question, I hope it helps you in a useful direction.

Add HomeScreen WebApps from another application? [duplicate]

Do you know is there a programmatic way to create a web shortcut on the phone user's home screen?
What I want to do is:
When the phone user clicks a button in our Android application, the application will then place a website shortcut onto the phone user's home screen.
First you'll need to add a permission to your manifest.xml
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT">
</uses-permission>
You'll need to build an intent to view the webpage. Something like...
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.blablaba.com"));
You can test this by creating a little test app and doing startActivity(i); This should open the browser. Once you verified that the above intent is correct you should move on to the next step.
Now you'll need to actually install the shortcut.
Intent installer = new Intent();
installer.putExtra("android.intent.extra.shortcut.INTENT", i);
installer.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", I THINK this is a bitmap); //can also be ignored too
installer.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(installer)
;
It's also possible some home screens don't accept this, but most do. So enjoy.
EDIT:
Icon can be set to the shortcut using:
installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon));
As an addition to the correct answer by #Mike-dg and #Gagan, instead of using
putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon))
which requires a ShortcutIconResource, you can use
putExtra("android.intent.extra.shortcut.ICON", Bitmap))
which lets you use any bitmap as the icon. This makes it easy to use a the favicon of the shortcut's website as the icon.
You can't place UI elements on the phone's home screen through an .apk. For the web shortcut - you can create a widget that opens the browser (with the specified URL) upon click.

Hide another app launcher icon in Android

I'm developing an Android app with a button that when that button pressed I want to hide WhatsApp launcher icon. How can I do that?
I know that I should use PakageManager but I have no idea how to use it. I found this code but I have no idea how to use it:
ComponentName componentToDisable = new ComponentName("target package name",
"target launcher activity");
getPackageManager().setComponentEnabledSetting(
componentToDisable,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
That is not possible, outside of some security flaw that I don't know of. Your app can disable your own app's components; your app cannot disable the components of other apps.

Allow a USER to remove app icon from Launcher?

I'm trying to programatically allow the USER to decide when to remove my app (a theme which is called from another app) from the launcher.
Currently using a button:
getPackageManager().setComponentEnabledSetting(new ComponentName("com.package.name","Main"),PackageManager.COMPONENT_ENABLED_STATE_DISABLED,0);
Sorry I'm not a coder and I'm doing something wrong, the button shows but no effect even with a launcher or phone restart.
Ideas?
OK, I actually found some other similar code which worked.
I had kept intent.category.LAUNCHER and intent.action.MAIN in Main and moved the intent that calls my app from a parent app into a new class (duh).
Then I run the folowing on a button press by which the user can remove the icon from the launcher (requires launcher/phone restart):
PackageManager pm = getPackageManager(); ComponentName name = new ComponentName(this, Main.class);
pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
Why is there even a launcher icon (necessary) in the first place? Does a theme need such an icon?
Apart from that: the same question was asked and answered here: you have to restart the launcher itself to update the icon-list.

Android: Is there a programming way to create a web shortcut on home screen

Do you know is there a programmatic way to create a web shortcut on the phone user's home screen?
What I want to do is:
When the phone user clicks a button in our Android application, the application will then place a website shortcut onto the phone user's home screen.
First you'll need to add a permission to your manifest.xml
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT">
</uses-permission>
You'll need to build an intent to view the webpage. Something like...
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.blablaba.com"));
You can test this by creating a little test app and doing startActivity(i); This should open the browser. Once you verified that the above intent is correct you should move on to the next step.
Now you'll need to actually install the shortcut.
Intent installer = new Intent();
installer.putExtra("android.intent.extra.shortcut.INTENT", i);
installer.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", I THINK this is a bitmap); //can also be ignored too
installer.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(installer)
;
It's also possible some home screens don't accept this, but most do. So enjoy.
EDIT:
Icon can be set to the shortcut using:
installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon));
As an addition to the correct answer by #Mike-dg and #Gagan, instead of using
putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon))
which requires a ShortcutIconResource, you can use
putExtra("android.intent.extra.shortcut.ICON", Bitmap))
which lets you use any bitmap as the icon. This makes it easy to use a the favicon of the shortcut's website as the icon.
You can't place UI elements on the phone's home screen through an .apk. For the web shortcut - you can create a widget that opens the browser (with the specified URL) upon click.

Categories

Resources