[英]How do I issue conversation notifications on Android 11, if I already have published 5 shortcuts?
According to “People and conversations” , one of the prerequisites for a conversation notification on Android 11 is the following:根据“人员和对话” ,Android 11 上的对话通知的先决条件之一如下:
The notification is associated with a valid long-lived dynamic or cached sharing shortcut.
该通知与有效的长期动态或缓存的共享快捷方式相关联。 The notification can set this association by calling
setShortcutId()
orsetShortcutInfo()
.通知可以通过调用
setShortcutId()
或setShortcutInfo()
来设置此关联。
But I can only have 5 shortcuts .但我只能有 5 个快捷方式。 Does this mean that I can't make conversations notifications for more than 5 people?
这是否意味着我不能为超过 5 人发送对话通知?
It appears that you can actually publish more than 5 shortcuts.看来您实际上可以发布超过 5 个快捷方式。 You can make notifications which would rank lower than all others by setting
rank
to a high number, and publish them using shortcutManager.pushDynamicShortcut()
.您可以通过将
rank
设置为高数字来制作排名低于所有其他通知的通知,并使用shortcutManager.pushDynamicShortcut()
发布它们。
In case you don't have any launcher shortcuts, the above action will create one.如果您没有任何启动器快捷方式,上述操作将创建一个。 If you don't want that, it's recommended to... simply remove the shortcut you just created :
如果您不希望这样,建议...只需删除您刚刚创建的快捷方式:
Q: Will my shortcuts appear in the long press app launcher context menu?
问:我的快捷方式会出现在长按应用启动器上下文菜单中吗? A: They can depending on their rank, but if you prefer not having shortcuts appear on launcher you can remove the shortcut with
ShortcutManager#removeDynamicShortcuts()
or#removeAllDynamicShortcuts()
after sending the notification.答:他们可以根据他们的等级,但如果您不希望在启动器上显示快捷方式,您可以在发送通知后使用
ShortcutManager#removeDynamicShortcuts()
或#removeAllDynamicShortcuts()
删除快捷方式。 You can also rank other app shortcuts with higher ranking, so only those dynamic shortcuts appear on launcher.您还可以对排名较高的其他应用快捷方式进行排名,因此只有那些动态快捷方式才会出现在启动器上。
Some thoughts follow below.下面是一些想法。 It appears that shortcuts on a regular phone will appear in three places:
普通手机上的快捷方式似乎会出现在三个地方:
These shortcuts all come from the same pool.这些快捷方式都来自同一个池。 It makes sense, but as there is only a single rank for every shortcut this means that the launcher list and the direct share list are the same.
这是有道理的,但由于每个快捷方式只有一个等级,这意味着启动器列表和直接共享列表是相同的。 This is something you might not want;
这是您可能不想要的; you might be sharing more to one conversation but opening another one more often.
您可能会在一个对话中分享更多内容,但更频繁地打开另一个对话。 In my app, I solved this in the following way:
在我的应用程序中,我通过以下方式解决了这个问题:
shortcutManager.pushDynamicShortcut()
;shortcutManager.pushDynamicShortcut()
更新快捷方式; if a shortcut with the same id already exists, it is updated.shortcutManager.getShortcuts()
.shortcutManager.getShortcuts()
的旧细节。
This allows having completely different launcher & direct share shortcuts, and to publish many a conversation notification.这允许拥有完全不同的启动器和直接共享快捷方式,并发布许多对话通知。
Some random observations:一些随机观察:
Adding a shortcut id to a conversation notification also adds its icon to the notification, even if you don't set one explicitly.向对话通知添加快捷方式 ID 也会将其图标添加到通知中,即使您没有明确设置。
shortcutManager.maxShortcutCountPerActivity
actually returns 15 (,) on my device (LineageOS). shortcutManager.maxShortcutCountPerActivity
实际上在我的设备 (LineageOS) 上返回 15 (,)。 even though the launcher & direct share only show the regular 4 icons.即使启动器和直接共享仅显示常规的 4 个图标。
If you update a shortcut name and/or icon, most of the time it will instantly update in launcher.如果您更新快捷方式名称和/或图标,大多数情况下它会立即在启动器中更新。 This includes pinned shortcuts.
这包括固定的快捷方式。
Use IconCompat.createWithAdaptiveBitmap()
to create icons that work well for various icon shapes.使用
IconCompat.createWithAdaptiveBitmap()
创建适用于各种图标形状的图标。 The system will keep a hold of the image, you don't need to keep it.系统会保留图像,您不需要保留它。 See the documentation for that method.
请参阅该方法的文档。
There are two other methods to be aware of:还有两种方法需要注意:
IconCompat.createWithAdaptiveBitmapContentUri()
is the same as the above but will work with content URIs. IconCompat.createWithAdaptiveBitmapContentUri()
与上述相同,但适用于内容 URI。 This is good for creating Person
for notifications, as this allows not keeping the icons in memory.这对于为通知创建
Person
很有用,因为这允许不将图标保留在 memory 中。 However, there is seemingly no way to pass URI permissions to shortcut manager, so this method can't be used.不过貌似没有办法将URI权限传递给快捷方式管理器,所以这个方法不能用。 (Please correct me if I'm wrong here!)
(如果我在这里错了,请纠正我!)
Edit: if you cancel the notification after inline (direct) reply, the system might decide to add your reply to it instead of actually cancelling it.编辑:如果您在内联(直接)回复后取消通知,系统可能会决定将您的回复添加到它而不是实际取消它。 Apparently it might lose URI permissions at this point.
显然,此时它可能会失去 URI 权限。 Calling this workaround on URIs seems to be helping:
在 URI 上调用此解决方法似乎有所帮助:
fun Uri.grantReadPermissionToSystem() { applicationContext.grantUriPermission("com.android.systemui", this, Intent.FLAG_GRANT_READ_URI_PERMISSION) }
IconCompat.createWithData()
creates memory efficient icons from compressed image data (PNG/JPEG). IconCompat.createWithData()
从压缩图像数据 (PNG/JPEG) 创建 memory 高效图标。 It's not adaptive, however.然而,它不是自适应的。 And, icons made with it don't work with
ShortcutManager
at all.而且,用它制作的图标根本不适用于
ShortcutManager
。
Also don't forget to check out the readme of the People sample app .另外不要忘记查看People 示例应用程序的自述文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.