【发布时间】:2017-11-06 22:40:14
【问题描述】:
背景
从 Android O 开始,可以创建固定快捷方式,它(在支持的启动器上)会显示一个对话框来确认它们的创建:
ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(context, uniqueShortcutId)
.setShortLabel(label)
.setIntent(shortcutIntent)
.setLongLabel(label)
.setIcon(IconCompat.createWithBitmap(bitmap))
.build();
ShortcutManagerCompat.requestPinShortcut(this, pinShortcutInfo , null);
文档:
https://developer.android.com/reference/android/content/pm/ShortcutManager.html https://developer.android.com/guide/topics/ui/shortcuts.html
问题
有时,固定的快捷方式不再相关。例如,它指向不再存在的东西。
在这种情况下,我希望能够将其删除。
我尝试过的
我认为下一个代码可以做到这一点,但事实并非如此,因为它可能与动态快捷方式有关,这是另一回事:
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);
问题
如何删除固定的快捷方式?有没有可能?
更新:似乎不可能,正如 Google 提到的 here。
到目前为止,这个 API 对我来说似乎很受限制,因为它有很多缺点:
- 无法从资源 ID 创建创建的图标图像。
- 在启动器上,创建的图标有一个创建它的应用的小图标。
- 无法通过 API 移除图标(仅禁用),因此如果您创建的图标指向另一个应用,而该应用已被移除,您将无法移除它。
- 创建不能在后台进行,因为它需要一个确认对话框。它也不能批量创建。一个接一个。
- 如果您的应用被删除,您的应用创建的所有固定快捷方式都将被删除。
所以,我现在的问题是:
是否有任何方法可以使用以前的 API 创建和删除快捷方式,使用 adb 命令,如果需要,使用 root 权限?
是否可以使用 adb 命令删除特定的固定快捷方式,如果需要,可以使用 root 权限?
【问题讨论】:
-
你有没有想过这个问题?
-
@AlexandruPetrescu 没有。遗憾的是没有......
-
@AlexandruPetrescu 我已经给出了我认为是这个问题的最佳答案。请在宽限期到期之前查看并奖励赏金。
标签: android android-8.0-oreo pinned-shortcut