Android and android Official Website

Source: Internet
Author: User

Android and android Official Website
Add

The add shortcut is to send a broadcast of related actions to the desktop application (launcher:

public static final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";

Code:

Private void addShortcut (String name) {Intent addShortcutIntent = new Intent (ACTION_ADD_SHORTCUT); // duplicate addShortcutIntent creation is not allowed. putExtra ("duplicate", false); // The results are not repeated based on the shortcut name.
// Name addShortcutIntent. putExtra (Intent. EXTRA_SHORTCUT_NAME, name); // icon addShortcutIntent. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, Intent. using cuticonresource. fromContext (MainActivity. this, R. drawable. ic_launcher); // sets the associated program Intent launcherIntent = new Intent (Intent. ACTION_MAIN); launcherIntent. setClass (MainActivity. this, MainActivity. class); launcherIntent. addCategory (Intent. CATEGORY_LAUNCHER); addShortcutIntent. putExtra (Intent. EXTRA_SHORTCUT_INTENT, launcherIntent); // send broadcast sendBroadcast (addShortcutIntent );}
Remove

Action:

public static final String ACTION_REMOVE_SHORTCUT = "com.android.launcher.action.UNINSTALL_SHORTCUT";

Code:

Private void removeShortcut (String name) {Intent intent = new Intent (ACTION_REMOVE_SHORTCUT); // name intent. putExtra (Intent. EXTRA_SHORTCUT_NAME, name); // sets the associated program Intent launcherIntent = new Intent (MainActivity. this, MainActivity. class ). setAction (Intent. ACTION_MAIN); intent. putExtra (Intent. EXTRA_SHORTCUT_INTENT, launcherIntent); // send broadcast sendBroadcast (intent );}

 

Permission
<! -- Add shortcuts --> <uses-permission android: name = "com. android. launcher. permission. INSTALL_SHORTCUT"/> <! -- Remove shortcuts --> <uses-permission android: name = "com. android. launcher. permission. UNINSTALL_SHORTCUT"/>
I am the dividing line of tiantiao

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.