1

I am trying to remove all shortcuts from all screens in android. I succeed it once but somehow it stopped working after next execute. Could I ask you to help me find out what would be the problem? There is not stack, there is no error, just I click and nothing happens. When I first managed to success I got many toasts describing that "X was removed".

Here is my code:

private void method0() {
    final Intent anyIntent = new Intent(Intent.ACTION_MAIN, null);
    List<ResolveInfo> pkgAppsList = this.getPackageManager().queryIntentActivities(anyIntent, 0);
    for (final ResolveInfo resolveInfo : pkgAppsList) {
                method(resolveInfo);
    }
}

private void method(ResolveInfo resolveInfo) {
    try {
        final PackageManager pm = getPackageManager();
        String packageName = ((ActivityInfo) resolveInfo.activityInfo).packageName;
        String appName = (String) resolveInfo.loadLabel(pm);
        ComponentName componentName = new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName, resolveInfo.activityInfo.name);

        if (packageName.startsWith("com.google") || (packageName.startsWith("com.android")))
            return;

        final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
        shortcutIntent.setComponent(new ComponentName(packageName, componentName.getClassName()));

        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
        intent.setComponent(new ComponentName(packageName, componentName.getClassName()));
        intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");

        sendBroadcast(intent, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

I added also permission

<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />   

I am using standard launcher for Nexus 4 - original image ROM from google site.

Siddiq Abu Bakkar
  • 1,949
  • 1
  • 13
  • 24
deadfish
  • 11,996
  • 12
  • 87
  • 136
  • 1
    See this one http://stackoverflow.com/questions/12853443/android-how-to-remove-uninstall-application-shortcuts-from-home-screen – Haresh Chhelana May 19 '14 at 10:40
  • 2
    There is no requirement for any home screen implementation to support the code that you have listed. – CommonsWare May 25 '14 at 01:08
  • 1
    @CommonsWare means _launcher apps are not required to add functionality to handle UNINSTALL_SHORTCUT intent and remove shortcuts from home screen_ – ozbek May 26 '14 at 03:02
  • I wanted to use on original rom for android withoud any additional launchers – deadfish May 26 '14 at 07:08

1 Answers1

0

Looks like you are not using default Stock android launcher.

Please check this example.Hope that helps.

vITs
  • 1,651
  • 12
  • 30
  • 1
    as I said it worked once and the somehow it stopped working. I am talking about all shortcuts on screens not only this shortcut for current app. – deadfish May 27 '14 at 11:35
  • Are you able to remove shortcut of current App every time? – vITs May 27 '14 at 11:44
  • Also check this [discussion](http://stackoverflow.com/questions/3480287/trying-to-uninstall-shortcut-but-shortcut-wont-go-away)? – vITs May 27 '14 at 11:57