The User Experience
From a sharing standpoint, the user experience is about what you would expect… albeit with a side-effect that may be less than ideal for some apps.
Sharing
If an app requests an ACTION_SEND
that matches your desired MIME type(s), your dynamic shortcuts will appear in the “share sheet”:
It is unclear how Android 10 will decide which of your share targets to show, if you have a lot of them.
If the user chooses one of those, your ACTION_SEND
activity will be started. Among the extras will be an Intent.EXTRA_SHORTCUT_ID
value that is the ID that you supplied to the ShortcutInfoCompat.Builder
for the dynamic shortcut. You can use this to look up relevant information to determine the context for the user’s choice of share targets.
Shortcuts
However, your share targets also show up as dynamic shortcuts:
This all but eliminates your app’s ability to use shortcuts for anything else.
It also means that your share targets have to make sense in cases where the user is not sharing anything, because they clicked a dynamic shortcut.
Apparently, this is working as intended.
If the user taps one of the dynamic shortcuts, whatever Intent
you gave to the ShortcutInfoCompat.Builder
will be invoked. This Intent
can be for whatever activity you want, not necessarily the ACTION_SEND
activity. In the sample module, we use ACTION_WHATEVER
for the Intent
and have a corresponding <intent-filter>
for it on MainActivity
, not on ShareActivity
.
Pre-10
If you named your shortcut XML resource shortcuts.xml
, then on Android 6.0-9.0 devices, your share targets will show up in the “share sheet”, courtesy of androidx.sharetarget
:
And, on Android 7.1-9.0 devices, your share targets will also show up as dynamic shortcuts.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.