Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use these methods to properly add or remove shortcuts. These methods are working pretty well and are the <strong>same as the Android System when the user manually add/remove a shortcut</strong>.</p> <pre><code>public static void addShortcut(Context context) { Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); ApplicationInfo appInfo = context.getApplicationInfo(); // Shortcut name shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, appInfo.name); shortcut.putExtra("duplicate", false); // Just create once // Setup activity shoud be shortcut object ComponentName component = new ComponentName(appInfo.packageName, appInfo.className); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(component)); // Set shortcut icon ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(context, appInfo.icon); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); context.sendBroadcast(shortcut); } public static void deleteShortcut(Context context) { Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); ApplicationInfo appInfo = context.getApplicationInfo(); // Shortcut name shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, appInfo.name); ComponentName comp = new ComponentName(appInfo.packageName, appInfo.className); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); context.sendBroadcast(shortcut); } </code></pre> <p>Permissions :</p> <pre><code>&lt;uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /&gt; &lt;uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /&gt; </code></pre> <p>BroadcastReceiver :</p> <pre><code>&lt;receiver android:name="YOUR.PACKAGE.PackageReplacedReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.PACKAGE_REPLACED" /&gt; &lt;data android:scheme="package" android:path="YOUR.PACKAGE" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload