Create Desktop shortcuts for android apps

Source: Internet
Author: User

Android shortcuts are simple, that is, sending a system broadcast and setting Intent --- package com. xikang. android. slimcoach. utils;/*** @ author huiych * Create a shortcut * @ created 2013-02-21 **/import android. content. intent; import android. OS. parcelable; import com. xikang. android. slimcoach. appXiKang; import com. xikang. android. slimcoach. r; import com. xikang. android. slimcoach. ui. appStart; public class ShortCutUtil {public static void initShortCut () {In Tent addShortCut = new Intent ("com. android. launcher. action. INSTALL_SHORTCUT cut "); // The shortcut cannot be created repeatedly. putExtra ("duplicate", false); String title = AppXiKang. getApp (). getString (R. string. app_name); // name Parcelable icon = Intent. using cuticonresource. fromContext (AppXiKang. getApp (), R. drawable. icon); // icon // click the shortcut to operate Intent. After the shortcut is created, start the program Intent intent = new Intent (AppXiKang. getApp (), AppStart. class ); // Set the shortcut title addShortCut. putExtra (Intent. EXTRA_SHORTCUT_NAME, title); // sets the shortcut icon addShortCut. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, icon); // sets the Intent addShortCut corresponding to the shortcut. putExtra (Intent. EXTRA_SHORTCUT_INTENT, intent); // Add a shortcut for sending broadcasts to AppXiKang. getApp (). sendBroadcast (addShortCut);} AppXiKange. getApp () is used to obtain the Activity object. Note: You must set the permission <uses-permission android: name = "com. android. launcher. permission. INSTALL_SHORTCUT "/> to add a shortcut, you can give the user an alertdialog, prompt, and reference it. You can. There are also many applications on the market that directly create shortcuts when installing applications. However, this implementation is not very friendly. It is not recommended.

Related Article

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.