Android 如何删除固定的快捷方式? 背景
从Android O开始,可以创建固定的快捷方式,该快捷方式(在受支持的启动器上)会显示一个对话框,以确认快捷方式的创建:Android 如何删除固定的快捷方式? 背景,android,android-8.0-oreo,pinned-shortcut,Android,Android 8.0 Oreo,Pinned Shortcut,从Android O开始,可以创建固定的快捷方式,该快捷方式(在受支持的启动器上)会显示一个对话框,以确认快捷方式的创建: ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(context, uniqueShortcutId) .setShortLabel(label) .setIntent(shortcut
ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(context, uniqueShortcutId)
.setShortLabel(label)
.setIntent(shortcutIntent)
.setLongLabel(label)
.setIcon(IconCompat.createWithBitmap(bitmap))
.build();
ShortcutManagerCompat.requestPinShortcut(this, pinShortcutInfo , null);
文件:
问题
有时,固定的快捷方式不再相关。例如,它指向不再存在的东西
在这种情况下,我希望能够删除它
我试过的
我认为在下一段代码中这是可能的,但事实并非如此,因为它可能是关于动态快捷方式的,这是另外一回事:
ShortcutManager shortcutManager = (ShortcutManager) getSystemService(SHORTCUT_SERVICE);
final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts();
final ArrayList<String> shortcutIdsToRemove = new ArrayList<>();
for (ShortcutInfo pinnedShortcut : pinnedShortcuts) {
final Intent pinnedShortcutIntent = pinnedShortcut.getIntent();
shortcutIdsToRemove.add(pinnedShortcut.getId());
}
shortcutManager.removeDynamicShortcuts(shortcutIdsToRemove);
// this also doesn't work : shortcutManager.disableShortcuts(shortcutIdsToRemove);
ShortcutManager ShortcutManager=(ShortcutManager)getSystemService(快捷方式服务);
最终列表pinnedShortcuts=shortcutManager.getPinnedShortcuts();
final ArrayList shortcutIdsToRemove=新ArrayList();
for(快捷键fo pinnedShortcut:pinnedShortcuts){
final-Intent-pinnedShortcutivent=pinnedShortcut.getIntent();
shortcutIdsToRemove.add(pinnedShortcut.getId());
}
shortcutManager.removeDynamicShortcuts(shortcutIdsToRemove);
//这也不起作用:shortcutManager.disableShortcuts(shortcutIdsToRemove);
问题
如何删除固定的快捷方式?有可能吗
更新:正如谷歌提到的,这似乎是不可能的 到目前为止,这个API对我来说似乎非常有限,因为它有很多缺点:
你发现了吗?@AlexandruPetrescu没有。遗憾的是没有…@AlexandruPetrescu我已经给出了我认为是这个问题最好的答案。请在宽限期结束前查看并奖励赏金。禁用是毫无用处的。用户看到一个他不能再使用的快捷方式,为什么要让它。。。你知道一种根目录的方式吗?或者使用旧的API创建和删除快捷方式?@androiddeveloper将你的应用程序限制为根目录用户是否真的值得?您被禁用的消息可能会简单地表示“此功能不再可用。快捷方式可能会被手动删除。”--用户可以自己删除。@androiddeveloper此外,即使您希望使用root用户来执行此操作,您也需要为您想要支持的每个可能的启动器以不同的方式处理删除操作。系统不保存快捷方式数据,启动器保存。我的意思是通过以前的API创建和删除。我认为,从Play Store安装应用程序时,会使用一个不需要用户确认的API创建快捷方式。也许是旧的。这也是为什么许多启动程序可以为新安装的应用程序设置快捷方式的原因,但只有在从Play Store安装应用程序时才有效,而不是通过普通APK文件安装。@androiddeveloper Play Store对其授予了特殊权限。它还可以自动启用“在其他应用之上绘制”权限,您必须手动为从其他任何位置安装的应用启用该权限。顺便说一句,甚至没有一个不推荐使用的用于删除快捷方式的API。只有在清除应用程序数据时,才会删除快捷方式,因此您可以尝试模拟“应用程序卸载”系统广播,这将导致启动器删除所有应用程序的快捷方式(您尝试重新添加)。简而言之,这是个坏主意,你不应该这么做。