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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With