卸载Android应用程序时,不会从主屏幕删除应用程序启动器图标

Vid*_*nes 7 icons android uninstall

我正在使用类似的代码片段,如下所示在主屏幕上添加应用程序快捷方式:

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(this, this.getClass().getName());
    shortcutIntent.putExtra(EXTRA_KEY, "ApiDemos Provided This Shortcut");

    // Then, set up the container intent (the response to the caller)

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_name));
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
            this,  R.drawable.app_sample_code);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher

    setResult(RESULT_OK, intent);
Run Code Online (Sandbox Code Playgroud)

创建快捷方式没有问题,但在卸载应用程序时,快捷方式仍保留在主屏幕上.卸载其他应用程序时,他们似乎也删除了相应的主屏幕快捷方式.这是我尝试使用"创建代码快捷方式图标"实现的目标

Stackoverflow上的任何Android专家是否都知道在卸载应用程序时从主屏幕删除应用程序快捷方式需要什么?

我发现了一些相关的线程,但它们没有为我提供解决方案,但请随时赶上:

[0] https://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html

[1] 在Android中以编程方式从启动器中删除应用程序

[2] 如何在卸载时自动从主屏幕删除应用程序快捷方式?

Eri*_*vik 4

我认为你可以尝试将此操作放在第二个意图中:“com.android.launcher.action.INSTALL_SHORTCUT”

这对我有用,启动器图标安装在主屏幕上,当我卸载应用程序时,该图标被删除。已经为此苦苦挣扎了一段时间。

Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(this, this.getClass().getName());

Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
            this,  R.drawable.launcher_icon);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。