Android--Create desktop shortcuts

Source: Internet
Author: User

Code

/*** * Returns the intent added to the desktop shortcut: * * 1. Assign action= "Com.android.launcher.INSTALL_SHORTCUT" to intent * 2. Set the intent that is defined as intent.extra_shortcut_inent to the action that is consistent with the installation (must have) * * 3. Add Permissions: Com.android.launcher.permission.INSTALL_ SHORTCUT*/     PublicIntent getshortcuttodesktopintent (context context) {Intent Intent=NewIntent ();        Intent.setclass (Context, Context.getclass ()); /*The following two sentences are used to remove the desktop shortcut while uninstalling the app*/Intent.setaction ("Android.intent.action.MAIN"); Intent.addcategory ("Android.intent.category.LAUNCHER"); Intent Shortcut=NewIntent ("Com.android.launcher.action.INSTALL_SHORTCUT"); //Rebuild not allowedShortcut.putextra ("Duplicate",false); //Set name//Shortcut.putextra (intent.extra_shortcut_name,context.getstring (R.string.app_name));Shortcut.putextra (Intent.extra_shortcut_name, "11111"); //Set iconShortcut.putextra (Intent.extra_shortcut_icon_resource, Intent.ShortcutIconResource.fromContext (        Context, r.drawable.youtube)); //Set Intent and shortcut Association programsShortcut.putextra (intent.extra_shortcut_intent, Intent); returnshortcut; }

Permissions

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

Call

 Public void Click1 (View v) {        this. Getshortcuttodesktopintent (mainactivity.  this);        Sendbroadcast (intent);    }

I'm the dividing line of the king of the Land Tiger.

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.