/** * has created a shortcut * @return */Private Boolean Hasshortcut () {Boolean isinstallshortcut = false; Final String authority = "com.android.launcher.settings"; Final Uri Content_uri = Uri.parse ("content://" +authority + "/favorites?notify=true"); Cursor C = getcontentresolver (). Query (Content_uri, new string[] {"title", "Iconresource"}, "Title=?", new string[] {SHOPD Etail.gettitle ()}, NULL); if (null! = C && c.getcount () > 0) {isinstallshortcut = true; } return isinstallshortcut; }/** * Create Shortcut */private void Addshortcut () {if (Hasshortcut ()) {return; } Intent shortcut = new Intent ("Com.android.launcher.action.INSTALL_SHORTCUT"); The name of the shortcut Shortcut.putextra (Intent.extra_shortcut_name, Shopdetail.gettitle () + "shop"); Duplicate creation of Shortcut.putextra ("duplicate", false) is not allowed; Specifies the object that the current activity initiates for the shortcut: CompOnentname comp = new ComponentName ("Com.itel.platform", "Com.itel.platform" + ".") + "ui.shop.ShopIndexActivity"); Shortcut.putextra (Intent.extra_shortcut_intent, New Intent (Intent.action_main). PutExtra ("Shopid", Ushopid). PutExtra ("OpenType", 1). SetComponent (comp)); The icon for the shortcut can be added with two types if (bitmap! = null) {Shortcut.putextra (Intent.extra_shortcut_icon, bitmap);//Picture with pictures , not using the current app picture} else {parcelable icon = Intent.ShortcutIconResource.fromContext (This, R.drawable.ic_laun Cher); Shortcut.putextra (Intent.extra_shortcut_icon_resource, icon);//set the icon}//Some Android version does not prompt, here manual prompt if (Build.VERSION.SDK_INT = = 10 | | Build.VERSION.SDK_INT >=) {T.S (context, "shortcut key" + shopdetail.gettitle () + "The store has been added"); } sendbroadcast (shortcut); }
Android Add shortcut to Desktop