4

I need to remove one particular (better) or all shortcuts (worst case) pointing to my app from stock launcher. I was unable to use UNINSTALL_SHORTCUT broadcast, it seems that it just dont work (simillar problem to this.

My app is signed by system certificate (it will be installed in /system/app) so I have some ideas, how to remove shortcuts.

  1. Is there a working way to use UNINSTALL_SHORTCUT in ics?

  2. I have seen that stock launcher removes all links pointing to my app when I uninstall it. Is there any way to simulate uninstalling (or send package_removed broadcast, having system privileges)? maybe write a part of package manager?

  3. If 2 is not possible is there any way I can cause package manager to send PACKAGE_REMOVED broadcast, by reinstallation/upgrading my app? (I can install/upgrade apps silently, because I have system privileges with INSTALL_PACKAGES permission).

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
POMATu
  • 3,422
  • 7
  • 30
  • 42

3 Answers3

4

I believe you would have another way to start your app besides from the shortcut.

To not show on the app drawer, just remove

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

from the manifest of your Activity and it won't show the shortcut

UPDATE: you could separate the shortcuts in a different app/apk and install the shortcut "app" when you need the shortcut and uninstall when not needed.

Marcio Covre
  • 4,556
  • 2
  • 22
  • 24
  • 3
    This makes no sense. You say you want to remove the shortcuts, but you also need to keep the shortcuts. wtf? – Kevin Coppock Jun 04 '12 at 18:31
  • 1
    I need to remove them from home screen. Then I will add different ones to home screen – POMATu Jun 06 '12 at 18:36
  • So you don't want an main application shortcut but also other shortcuts. So the answer is the same, for each activity that you want to show on home screen you put the intent filter above and remove the intent if you don't want to show on that activity. Each activity that show a shortcut on homescreen has this intent. – Marcio Covre Jun 11 '12 at 12:19
  • I don't think is possible to do this on runtime. But since you have system permission to install/uninstall apps, you could separate the shortcuts in a different app/apk and install the shortcut "app" when you need the shortcut and uninstall when not needed. – Marcio Covre Jun 12 '12 at 17:15
  • 1
    I did it like that now. Installed shortcuts, when I need shortcuts I am uninstalling my app, launcher cleans all shortcuts related to my app, then install changed shortcuts. – POMATu Jun 12 '12 at 19:43
2

It seems UNINSTALL_SHORTCUT does not working with a EXTRA_SHORTCUT_NAME witch have space key.

try to remove the space key from the EXTRA_SHORTCUT_NAME.

This worked for me :

private void deleteShortCut(Context context) {

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra("someParameter", "HelloWorld");

    Intent removeIntent = new Intent();
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName");
    removeIntent.putExtra("duplicate", false);

    removeIntent
            .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");       
    context.sendBroadcast(removeIntent);
}

private void addShortCut(Context context) {

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra("someParameter", "HelloWorld");

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context,
                    R.drawable.ic_launcher));

    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
}
farmer.chs
  • 1,409
  • 1
  • 10
  • 3
  • 1
    still cant get this working. It says that app is not installed (when I click on shortcut), and does not deletes it. Can you share your working sample project? Seems like I have missed something – POMATu Jun 12 '12 at 13:28
  • My sample project is same as that in the Thread:http://forum.xda-developers.com/showthread.php?t=1583732. I just remove the space key from the EXTRA_SHORTCUT_NAME – farmer.chs Jun 13 '12 at 12:50
  • I just noticed the same thing with the space in the extra_shortcut_name, thanks for the tip. – logray Feb 05 '13 at 03:35
1

To remove shortcut:

you can tap and hold on a shortcut and drag that shortcut to the trash bin at the bottom to get rid of it. Once it turns red, let go. The shortcut will be deleted but the app will remain installed.

To Add shortcut:

Once you've found an app that you want to create a shortcut to, you'll want to tap and hold on the application.The applications menu will disappear and you'll be back at your home screen. You can drag the app icon left or right to view different home screens. Release the app to place the shortcut wherever you wish.

Jai
  • 19
  • 1
  • 5
    The original poster is asking how to programatically remove the shortcut to his app from his users devices, not how to remove a shortcut from his own. – Blumer Oct 10 '12 at 18:30