Android APK installation automatically creates a shortcut icon on the desktop

Source: Internet
Author: User

You can see a lot of apps that pop up after the first run and say what shortcuts have been created, so how did this thing come out?

It's simple, just a few words, write it down here, copy it.

Create a class first

1 Importandroid.app.Activity;2 Importandroid.content.Intent;3 Importandroid.os.Parcelable;4 5 /**6 * Created by Administrator on 2016/1/21.7  */8  Public classShortCut {9      Public Static voidCreateShortcut (Activity Act,intIconresid,intAppnameresid) {TenIntent Intent =NewIntent ("Com.android.launcher.action.INSTALL_SHORTCUT"); One       //do not allow duplicate creation AIntent.putextra ("Duplicate",false); -       //need a real name -       Intent.putextra (intent.extra_shortcut_name,act.getstring (Appnameresid)); the      //Quick Picture -parcelable icon =Intent.ShortcutIconResource.fromContext (Act.getapplicationcontext (), iconresid); -       Intent.putextra (Intent.extra_shortcut_icon_resource, ICON); -       //Click on the quick picture to run the program +Intent.putextra (Intent.extra_shortcut_intent,NewIntent (Act.getapplicationcontext (), Act.getclass ())); -       //Send broadcast +       Act.sendbroadcast (intent); A  at     } -}

The above code

First generate an Intent instance (implicit intent), and then put some values into intent to configure

Above is a 4 value to control the creation of the shortcut icon

1. Do you want to allow duplicate creation

2. Determine the name of the icon created

3. Determine the picture of the icon created

4. Set click on this shortcut icon to run the app

You can create a shortcut icon by invoking the static method of the class in the first activity while your app is running for the first time.

Finally, don't forget to add permissions

<uses-permission android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>

Android APK installation automatically creates a shortcut icon on the desktop

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.