Android Add shortcut to Desktop

Source: Internet
Author: User

/** * 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

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.