Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I place app icon on launcher home screen?

Tags:

android

As you know, when app is nomally installed, icon is created at launcher menu screen. What I want to do is create icon at user home screen during installation. (without pressing icon for 5 seconds.)

I heard this from another source to just add

<category android:value="android.intent.category.HOME" />

to AndroidManifest.xml file, but it didn't work.

Is there any other way to do it?

like image 786
respree Avatar asked Jan 31 '11 17:01

respree


2 Answers

You can use this:

Intent shortcutIntent = new Intent();
shortcutIntent.setClassName("packageName", "className");
//shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "shortcut_name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
//intent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            context.sendBroadcast(addIntent);

You have to use following permission in your AndroidManaifest.xml

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

You can use the commented code according to your requirements.

Note that, perhaps, above API is not documented. But it works.

like image 78
Vasu Avatar answered Oct 17 '22 16:10

Vasu


This is now solved by the Google Play services. You don't have to add any codes to do it anymore. Now when you install an app from the Google Play Store it automatically creates the logo in the main screen. It can be handled in the Google Play store settings. Exception : If you are using any custom roms or launchers, it does not work with some.

like image 26
Amalan Dhananjayan Avatar answered Oct 17 '22 17:10

Amalan Dhananjayan