SoFunction
Updated on 2025-03-10

How to add (create), delete and determine whether desktop shortcuts exist on Android

How to add (create), delete and determine whether desktop shortcuts exist on Android

Updated: May 21, 2015 10:12:01 Author: 3H
This article mainly introduces Android's methods to add (create), delete and determine whether there are desktop shortcuts. It involves Android's related operation skills for desktop shortcuts. Friends who need it can refer to it.

This article describes the methods of adding (creating), deleting and determining whether there is a desktop shortcut on Android. Share it for your reference. The specific implementation method is as follows:

/**
 * Determine whether the desktop has added a shortcut
 *
 * @param cx
 * @param titleName
 * Shortcut name
 * @return
 */
public static boolean hasShortcut(Context cx) {
boolean result = false;
// Get the current application nameString title = null;
try {
final PackageManager pm = ();
title = (
((),
PackageManager.GET_META_DATA)).toString();
} catch (Exception e) {
}
final String uriStr;
if (.SDK_INT < 8) {
uriStr = "content:///favorites?notify=true";
} else {
uriStr = "content://./favorites?notify=true";
}
final Uri CONTENT_URI = (uriStr);
final Cursor c = ().query(CONTENT_URI, null,
"title=?", new String[] { title }, null);
if (c != null && () > 0) {
result = true;
}
return result;
}
/**
 * Delete the desktop shortcut for the current application
 *
 * @param cx
 */
public static void delShortcut(Context cx) {
Intent shortcut = new Intent(
".UNINSTALL_SHORTCUT");
// Get the current application nameString title = null;
try {
final PackageManager pm = ();
title = (
((),
PackageManager.GET_META_DATA)).toString();
("test", "title:" + title);
} catch (Exception e) {
}
// Shortcut name(Intent.EXTRA_SHORTCUT_NAME, title);
Intent shortcutIntent = ()
.getLaunchIntentForPackage(());
(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
(shortcut);
}
/**
 * Add desktop shortcuts to the current app
 *
 * @param cx
 * @param appName
 * Shortcut name
 */
public static void addShortcut(Context cx) {
Intent shortcut = new Intent(
".INSTALL_SHORTCUT");
Intent shortcutIntent = ()
.getLaunchIntentForPackage(());
(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// Get the current application nameString title = null;
try {
final PackageManager pm = ();
title = (
((),
PackageManager.GET_META_DATA)).toString();
("test", "title:" + title);
} catch (Exception e) {
}
// Shortcut name(Intent.EXTRA_SHORTCUT_NAME, title);
// Repeated creation is not allowed (not necessarily valid)("duplicate", false);
// Shortcut iconParcelable iconResource = (cx, );
(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
(shortcut);
}

I hope this article will be helpful to everyone's Android programming design.

  • Android
  • desktop
  • Shortcuts

Related Articles

  • Detailed explanation of the steps to implement offline data synchronization in Android applications

    When building Android applications, offline data synchronization is an indispensable link. Whether it is the poor network condition or the user is in flight mode, offline data synchronization allows users to continue using the application without a network. This article will introduce in detail how to achieve offline data synchronization in Android applications. Friends who need it can refer to it.
    2024-08-08
  • Android development example code of drag bar/sliding bar control and star rating control function

    This article mainly introduces the example codes of the drag bar/sliding bar control and star rating control functions in Android development. Friends who need it can refer to it
    2019-05-05
  • Android uses Service to develop simple music playback functions

    This article mainly introduces Android to use Service to develop simple music playback functions. The example code is introduced in this article in detail, which has certain reference learning value for everyone's learning or work. Friends who need it, please learn with the editor below.
    2023-04-04
  • Quick introduction and interpretation of Android annotation basic introduction

    First of all, what is annotation and what is its function? This article explains the most basic content and example interpretation of Android annotations
    2018-09-09
  • Android Development Self-study Notes (VI): Declare permissions and Activity

    This article mainly introduces the self-study notes on Android development (VI): Declare permissions and Activity. This article is a supplement to the previous article. Friends who need it can refer to it.
    2015-04-04
  • Android audio and video development hardware decoding component MediaCodec explanation

    In Android development, MediaCodec is provided to implement audio and video encoding and decoding tools. The corresponding decoder can be created for the corresponding audio and video decoding types through this class to decode the data. This article explains the use of MediaCodec in detail through examples. If you need it, please refer to it.
    2023-01-01
  • Android implements image grayscale, linear grayscale changes and binary processing methods

    This article mainly introduces the methods of image grayscale, linear grayscale changes and binary processing for Android. The editor thinks it is quite good. I will share it with you now and give you a reference. Let's take a look with the editor
    2018-10-10
  • Detailed explanation of TabLayout usage and custom style

    This article mainly introduces detailed explanation of the usage of TabLayout and related information about custom styles. Friends who need it can refer to it
    2017-01-01
  • Detailed explanation of the DIY effect of Android menu bar

    This article mainly introduces the detailed explanation of the Android menu bar DIY effect. Friends in need can refer to it for reference. I hope it can be helpful. I wish you more progress and get a promotion as soon as possible.
    2022-09-09
  • Android uses hover component to monitor mouse movement events

    This article mainly introduces the method of Android to monitor mouse movement events based on the hover component. It analyzes the operation skills of the hover component to monitor the changes of the mouse cursor on the view in combination with the example form. Friends who need it can refer to it.
    2017-02-02

Latest Comments