According to “People and conversations”, one of the prerequisites for a conversation notification on Android 11 is the following:
The notification is associated with a valid long-lived dynamic or cached sharing shortcut. The notification can set this association by calling
setShortcutId()
orsetShortcutInfo()
.
But I can only have 5 shortcuts. Does this mean that I can't make conversations notifications for more than 5 people?
It appears that you can actually publish more than 5 shortcuts. You can make notifications which would rank lower than all others by setting
rank
to a high number, and publish them usingshortcutManager.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:
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()
; if a shortcut with the same id already exists, it is updated. I use the old details fromshortcutManager.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.
shortcutManager.maxShortcutCountPerActivity
actually returns 15 (!) on my device (LineageOS), even though the launcher & direct share only show the regular 4 icons.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. 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. This is good for creatingPerson
for notifications, as this allows not keeping the icons in memory. However, there is seemingly no way to pass URI permissions to shortcut manager, so this method can't be used. (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. Calling this workaround on URIs seems to be helping:
IconCompat.createWithData()
creates memory efficient icons from compressed image data (PNG/JPEG). It's not adaptive, however. And, icons made with it don't work withShortcutManager
at all.Also don't forget to check out the readme of the People sample app.