Add desktop shortcuts to your app in Android

Source: Internet
Author: User

 Public voidShortCut (view view) {Createdeskshortcut ( This, GetString (R.string.short_cut), R.drawable.ups_icon, "http://www.baidu.com"); Createdeskshortcut ( This, GetString (R.STRING.SHORT_CUT2), R.drawable.ups_icont, "http://image.baidu.com/"); Toast.maketext ( This, "Create complete", 1). Show (); }     /*** Create Shortcut*/     Public voidCreatedeskshortcut (Context context,string name,inticonres,string URL) {LOG.I ("Javen", "------createshortcut--------"); //Intent to create a shortcutIntent shortcutintent =NewIntent ("Com.android.launcher.action.INSTALL_SHORTCUT"); //do not allow duplicate creationShortcutintent.putextra ("Duplicate",false); //need a real nameShortcutintent.putextra (Intent.extra_shortcut_name, NAME); //Quick Pictureparcelable icon =Intent.ShortcutIconResource.fromContext (Getapplicationcontext (), iconres); Shortcutintent.putextra (Intent.extra_shortcut_icon_resource,icon);//Intent Intent = new Intent (Getapplicationcontext (),//mainactivity.class);Intent Intent =NewIntent (intent.action_view,uri.parse (URL)); //The following two properties are intended to remove a shortcut on the desktop when the application is uninstalledIntent.setaction ("Android.intent.action.MAIN"); Intent.addcategory ("Android.intent.category.LAUNCHER"); //Click on the shortcut picture, run the program main entranceShortcutintent.putextra (intent.extra_shortcut_intent,intent); //send a broadcast. OKSendbroadcast (shortcutintent); }

When you uninstall your application you will find that there is a problem that your application is uninstalled, but the shortcut on the desktop is not uninstalled. Oh, in fact, you just need to set the corresponding boot into the intent plus so the following two properties is to show that your app is bound.

           /// the following two properties are intended to remove intent.setaction ("Android.intent.action.MAIN") when the application is uninstalled and the shortcut on the desktop is removed           ;           Intent.addcategory ("Android.intent.category.LAUNCHER");

Don't forget to add the following permissions to the Androidmanifest.xml:

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

Add desktop shortcuts to your app in Android

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.