Android--ShortCut

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.