Reputation:
I am pretty certain this is not a duplicate question.
I have read a lot of articles on creating a shortcut on homescreen to launch your own application, but I am struggling to create an icon for 3rd party app.
I can check if a given package name contains a launch intent by calling PM.getLaunchIntentForPackage(packageName).
Once a confirm that the above packageName has a launch intent, I do I use the packageName to create an icon to the default activity when user presses the icon of the package.
Thank you.
Upvotes: 0
Views: 848
Reputation:
After further searching and prior hours searching, I could not find the answer, but I finally worked it out myself. I am pretty certain someone will find this helpful:
Intent shortcutIntent = getPackageManager().getLaunchIntentForPackage(packageName);
Intent.ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Test");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
The key lies in "getPackageManager().getLaunchIntentForPackage(packageName)"
Upvotes: 1