Add
Adding a shortcut is a broadcast that sends a related action to the Desktop App (launcher):
Public Static Final String action_add_shortcut = "Com.android.launcher.action.INSTALL_SHORTCUT";
Code:
Private void addshortcut (String name) { new Intent (action_add_shortcut); // do not allow duplicate creation false); // The test is not repeated according to the name of the shortcut.
//nameAddshortcutintent.putextra (Intent.extra_shortcut_name, NAME); //iconsAddshortcutintent.putextra (Intent.extra_shortcut_icon_resource, Intent.ShortcutIconResource.fro Mcontext (mainactivity. This, R.drawable.ic_launcher)); //set up affiliate programsIntent launcherintent =NewIntent (Intent.action_main); Launcherintent.setclass (mainactivity. This, Mainactivity.class); Launcherintent.addcategory (Intent.category_launcher); Addshortcutintent.putextra (Intent.extra_shortcut_intent, launcherintent); //Send broadcastSendbroadcast (addshortcutintent); }
removed from
Action
Public Static Final String action_remove_shortcut = "Com.android.launcher.action.UNINSTALL_SHORTCUT";
Code:
Private voidremoveshortcut (String name) {Intent Intent=NewIntent (action_remove_shortcut); //nameIntent.putextra (Intent.extra_shortcut_name, NAME); //set up affiliate programsIntent launcherintent =NewIntent (mainactivity. This, Mainactivity.class). Setaction (Intent.action_main); Intent.putextra (Intent.extra_shortcut_intent, launcherintent); //Send broadcastSendbroadcast (Intent); }
Permissions
<!-- add shortcut --> < uses-permission Span style= "color: #ff0000;" >android:name = "Com.android.launcher.permission.INSTALL_SHORTCUT" Span style= "color: #0000ff;" >/> <!-- remove shortcut --> < uses-permission Span style= "color: #ff0000;" >android:name = "Com.android.launcher.permission.UNINSTALL_SHORTCUT" />
I'm the dividing line of the king of the land Tiger.
Android--ShortCut