SoFunction
Updated on 2025-04-06

Android programming method to create shortcuts for programs

This article describes the method of Android programming to create shortcuts for programs. Share it for your reference, as follows:

/**
 * Create desktop shortcuts for the program
 */
private void addShortcut(){
Intent shortcut = new Intent(".INSTALL_SHORTCUT");
//The name of the shortcut(Intent.EXTRA_SHORTCUT_NAME, getString(.app_name));
("duplicate", false); //Repeated creation is not allowed//Specify the object to which the current Activity is started as a shortcut://
//Note: The second parameter of ComponentName must be added with a dot (.), otherwise the shortcut cannot start the corresponding program.ComponentName comp = new ComponentName((), "."+());
(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
//Shortcut IconShortcutIconResource iconRes = (this, );
(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
}

I hope this article will be helpful to everyone's Android programming design.