如何从主屏幕删除应用程序快捷方式上卸载automaticaly? [英] How to remove application shortcut from home screen on uninstall automaticaly?

查看:403
本文介绍了如何从主屏幕删除应用程序快捷方式上卸载automaticaly?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发展,应该增加它的安装后的快捷方式到主屏幕,并删除它的应用程序被卸载后的应用程序。的应用将pinstalled在最终用户设备上$ P $,但仍应该有卸载的一个选项)。这个任务看起来很简单,但我已经遇到很多麻烦实施它。

I'm developing an application that should add it's shortcut to home screen after installation and remove it after the application is being uninstalled. The application will be preinstalled on the end user device, but still should have an option for uninstall). The task looks very simple but I've faced lots of troubles implementing it.

我做了什么:

  • 添加快捷方式到主屏幕使用 com.android.launcher.action.INSTALL_SHORTCUT 在应用程序第一次启动或蝾螈设备 重启。
  • MANUALY使用删除快捷方式 com.android.launcher.action.UNINSTALL_SHORTCUT。
  • Add shortcut to the home screen using com.android.launcher.action.INSTALL_SHORTCUT on app first launch or on newt device reboot.
  • MANUALY remove shortcut using com.android.launcher.action.UNINSTALL_SHORTCUT.

我不能(而且几乎放弃):

  • Automaticaly删除快捷方式时, 该应用程序正在卸载。
  • Automaticaly remove the shortcut when the application is being uninstalled.

有没有办法使用Intent.ACTION_PACKAGE_REMOVED因为应用程序正在卸载不会收到此意图。 我进行了一些测试,并发现了正在与应用程序中删除的唯一捷径类型是从菜单中创建快捷方式添加到主屏幕=>快捷方式=>应用程序=>应用程序活动。正在编程创建或在AndroidManifest声明的快捷方式留在主屏幕上的应用程序卸载后。

There's not way to use Intent.ACTION_PACKAGE_REMOVED because the application being uninstalled does not receive this intent. I performed some tests and found out that the only shortcut type that is being removed with the application is the shortcut that is created from menu 'Add to home screen => Shortcuts => Applications => Application activity'. The shortcuts that are being created programatically or that are declared in AndroidManifest remain on home screen after the app is uninstalled.

有几乎没有任何文档和帖子上有关此主题的论坛,我很困惑一点点,为什么这样一个简单的操作,不与Android安全政策的矛盾不能在一条直线的方式来实现。

There's almost none docs and posts on forums about this topic and I'm confused a little bit why such a simple operation that doesn't contradict with the Android security policy could not be implemented in a straight way.

有什么办法要求的操作系统,以消除应用程序卸载相应的快捷方式? 我能赶上的情况下,该应用程序被删除之前被卸载?

Is there any way to ask OS to remove the corresponding shortcut on application uninstall? Can I catch the event that the application is being uninstalled before it is removed?

推荐答案

看来你不使用install_shortcut意图正确的方式。也许你打造不带任何参数的意图。你应该用行动创造意图的 Intent.ACTION_MAIN 参数。

Seems that you don't use install_shortcut intent in right way. Probably you create an intent without any parameters. You should to create intent with an action Intent.ACTION_MAIN param.

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

这篇关于如何从主屏幕删除应用程序快捷方式上卸载automaticaly?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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