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