Or how to say Android is particularly open, and in Android development, just send a broadcast and it's going to happen.
Needless to say, the following is a piece of code that encapsulates well.
Copy Code code as follows:
public class Shortcututil {
public static void CreateShortcut (Activity Act, int iconresid,
int Appnameresid) {
Com.android.launcher.permission.INSTALL_SHORTCUT
Intent shortcutintent = new Intent (
"Com.android.launcher.action.INSTALL_SHORTCUT");
Do not allow duplicate creation
Shortcutintent.putextra ("duplicate", false);
Need a realistic name
Shortcutintent.putextra (Intent.extra_shortcut_name,
Act.getstring (APPNAMERESID));
Quick picture
parcelable icon = Intent.ShortcutIconResource.fromContext (
Act.getapplicationcontext (), iconresid);
Shortcutintent.putextra (Intent.extra_shortcut_icon_resource, ICON);
Click on the quick picture to run the program main entrance
Shortcutintent.putextra (Intent.extra_shortcut_intent,
New Intent (Act.getapplicationcontext (), Act.getclass ()));
Send broadcast
Act.sendbroadcast (shortcutintent);
}
}
The code is simpler and does not explain in more detail.
Don't forget to add the following permissions, otherwise you won't see any effect.
<uses-permission android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>
In addition, this may not be friendly. Better yet, when you first run the program, you are prompted to create a desktop shortcut for the user to choose from. Run again later will not be prompted.