SoFunction
Updated on 2025-04-10

Analyze the implementation method of automatically creating desktop shortcuts after Android application is started


public class ShortcutUtil { 

    public static void createShortCut(Activity act, int iconResId, 
            int appnameResId) { 

        // .INSTALL_SHORTCUT  

        Intent shortcutintent = new Intent( 
                ".INSTALL_SHORTCUT"); 
// Repeated creation is not allowed
        ("duplicate", false); 
// Need a realistic name
        (Intent.EXTRA_SHORTCUT_NAME, 
                (appnameResId)); 
// Quick pictures
        Parcelable icon = ( 
                (), iconResId); 
        (Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); 
// Click on the shortcut picture to run the main entrance of the program
        (Intent.EXTRA_SHORTCUT_INTENT, 
                new Intent((), ())); 
// Send broadcast
        (shortcutintent); 
    }