and*_*per 11 android android-8.0-oreo pinned-shortcut
从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);
Run Code Online (Sandbox Code Playgroud)
文档:
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);
Run Code Online (Sandbox Code Playgroud)
如何删除固定快捷方式?它甚至可能吗?
更新:似乎不可能,正如谷歌在这里提到的那样.
到目前为止,这个API对我来说似乎非常有限,因为它有很多缺点:
那么,我现在的问题是:
有没有办法使用adb命令使用以前的API创建和删除快捷方式,如果需要,可以使用root?
是否可以使用adb命令删除特定的固定快捷方式,如果需要可以使用root?
disableShortcuts()是你能做的最好的事情。当用户尝试选择禁用的快捷方式时,它将向用户显示自定义错误消息。
来自官方文档:
快捷方式限制 虽然您一次最多可以为应用程序发布五个快捷方式(静态和动态快捷方式组合),但大多数启动器只能显示四个。
但是,用户可以创建的应用程序固定快捷方式的数量没有限制。即使您的应用程序无法删除固定的快捷方式,它仍然可以禁用它们。
另一部分:
由于您的应用及其用户可以将快捷方式固定到设备的启动器,因此这些固定的快捷方式可能会将用户引导至您的应用中已过时或不再存在的操作。要管理这种情况,您可以通过调用disableShortcuts()来禁用不希望用户选择的快捷方式,这会从静态和动态快捷方式列表中删除指定的快捷方式,并禁用这些快捷方式的任何固定副本。您还可以使用此方法的重载版本,它接受 CharSequence 作为自定义错误消息。当用户尝试启动任何禁用的快捷方式时,就会出现该错误消息。
注意:如果您在更新应用程序时删除了应用程序的某些静态快捷方式,系统会自动禁用这些快捷方式。
| 归档时间: |
|
| 查看次数: |
1858 次 |
| 最近记录: |