卸载 Android 应用程序时,应用程序启动器图标不会从主屏幕中删除
我正在使用类似的代码片段(如下所示)在主屏幕上添加应用程序快捷方式:
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>
我找到了一些相关的线程,但它们没有为我的问题提供解决方案,但请随时跟进:
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:
[1] Remove application from launcher programatically in Android
[2] How to remove application shortcut from home screen on uninstall automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可以尝试将此操作放在第二个意图中:“com.android.launcher.action.INSTALL_SHORTCUT”
这对我有用,启动器图标安装在主屏幕上,当我卸载应用程序时,该图标被删除。已经为此苦苦挣扎了一段时间。
希望这有帮助。
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.
Hope this helps.
我也有同样的问题。
最后,我发现在创建应用程序的快捷方式时,应用程序的意图必须包含
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 thecom.android.launcher.action.INSTALL_SHORTCUT
action) .Hope it helps.