Analysis of the implementation method of automatically creating desktop shortcuts after Android application starts _android

Source: Internet
Author: User

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.

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.