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

发布于 2024-09-11 04:18:46 字数 1671 浏览 2 评论 0原文

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

    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);

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

Stackoverflow 上的 Android 专家知道卸载应用程序时从主屏幕删除应用程序快捷方式需要什么吗?< /strong>

我找到了一些相关的线程,但它们没有为我的问题提供解决方案,但请随时跟进:

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

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

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

I'm using a similar codesnippet as shown below to add an application shortcut on the homescreen:

    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);

There is no problem with creating the shortcut, but when uninstalling the app, the shortcut remains on the homescreen. When uninstalling other apps they all seem to also remove their corresponding homescreen shortcuts. This is what i try to achieve with my "created-by-code-shortcut-icon"

Does any of you Android experts here on Stackoverflow know whats needed to remove the app shortcut from the homescreen when the app is uninstalled ?

I found some related threads, but they do not provide me the solution for my problem, but please feel free to catch up:

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

[1] Remove application from launcher programatically in Android

[2] How to remove application shortcut from home screen on uninstall automatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那片花海 2024-09-18 04:18:46

我认为您可以尝试将此操作放在第二个意图中:“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);

希望这有帮助。

I think you can try putting this action in the second Intent: "com.android.launcher.action.INSTALL_SHORTCUT"

This works for me, the launcher icon gets installed on the home screen, and when I uninstall the application, the icon is removed. Have been struggling some time with this.

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);

Hope this helps.

难得心□动 2024-09-18 04:18:46

我也有同样的问题。

最后,我发现在创建应用程序的快捷方式时,应用程序的意图必须包含 Intent.ACTION_MAIN 操作,否则在卸载应用程序时快捷方式将不会从主屏幕中删除(而不是意图)用于安装快捷方式,该快捷方式具有 com.android.launcher.action.INSTALL_SHORTCUT 操作)。

希望有帮助。

I had the same problem as well.

Finally, i've figured out that when creating application's shortcut, application's intent must contain the Intent.ACTION_MAIN action, otherwise the shortcut won't be removed from the home screen upon uninstalling the application (not the intent being used for installing the shortcut, which has the com.android.launcher.action.INSTALL_SHORTCUT action) .

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文