从主屏幕卸载Android应用程序时,应用程序启动图标不会被删除 [英] Application launcher icon is not deleted from Home screen when uninstalling android app

查看:178
本文介绍了从主屏幕卸载Android应用程序时,应用程序启动图标不会被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个类似的codesnippet如下图所示添加主屏幕上的应用程序快捷方式:

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

有与创建快捷方式,但在卸载应用程序时,该快捷方式仍保留在主屏幕没有问题。当卸载其他应用程序,他们似乎都还删除其对应的主屏幕上的快捷方式。这是我尝试才达到我的创建逐code-快捷方式图标

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 achive with my "created-by-code-shortcut-icon"

是否有你的Andr​​oid专家在这里的#1知道什么是需要从主屏幕删除应用程序快捷方式,当应用程序被卸载?

我发现了一些相关的主题,但他们没有向我提供了我的问题的解决方案,但请随时追赶:

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

[0] <一个href="http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html">http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html

[1] <一个href="http://stackoverflow.com/questions/972933/remove-application-from-launcher-programatically-in-android">http://stackoverflow.com/questions/972933/remove-application-from-launcher-programatically-in-android

[2] <一个href="http://stackoverflow.com/questions/2131690/how-to-remove-application-shortcut-from-home-screen-on-uninstall-automaticaly">http://stackoverflow.com/questions/2131690/how-to-remove-application-shortcut-from-home-screen-on-uninstall-automaticaly

推荐答案

我觉得你可以尝试把这个动作在第二个意图: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.

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.

这篇关于从主屏幕卸载Android应用程序时,应用程序启动图标不会被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆