![](/img/trans.png)
[英]How to detect android app shortcut is removed from the Home Screen by the user?
[英]How to detect shortcut in Home screen
我有一个应用程序,允许您在主屏幕中创建“快捷方式”。 但我可以检测到“快捷方式”是否已经存在,我不必再次创建它。 谢谢。
我遇到了同样的问题。 我不认为它可能会告诉你它是否存在,但我认为我使用的也适合你。
只需在添加快捷方式之前卸载快捷方式!
intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
只需确保将以下内容添加到清单文件中即可。
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
我不知道是否可以检测到快捷方式,但是不是卸载然后安装,而是可以使用Extra字段作为
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
...
intent.putExtra("duplicate", false);
...
sendBroadcast(intent);
我想我找到了一个很好的方法来确保快捷方式不会多次添加,并且Toast消息也会消失。 创建一个int或boolean(我用了一个int)并将以下内容放在onResume中:
if(shortcut != 1) //or shortcut == true
{
...(shortcut code)...
shortcut = 1;
savePref("shortcut", shortcut); //overriding method to save int's or booleans
}
如果用户删除用户数据,那么它将添加另一个快捷方式到主屏幕,但我可以忍受,因为大多数用户无论如何都不删除那种东西,除非他们正在卸载应用程序。 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.