0

Is there a way to launch the Sharesheet (see https://developer.android.com/training/sharing/send) without having to wrap the called intent into the createChooser-returned intent, but rather specifying the wish for the Sharesheet as an ACTION and/or EXTRA. E.g. instead of

val sendIntent: Intent = Intent().apply {
    action = Intent.ACTION_SEND
    putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
    type = "text/plain"
}

val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)

Something like:

val shareIntent: Intent = Intent().apply {
    action = Intent.ACTION_CREATE_CHOOSER
    putExtra(Intent.EXTRA_ACTION_TYPE, Intent.ACTION_SEND)
    putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
    type = "text/plain"
}

startActivity(shareIntent)

My main goal is to get a Sharesheet that shows my frequent contacts/apps at the top. I'm not interested in all the functionality that createChooser might provide.

Should work at least in Android 11.

jps
  • 20,041
  • 15
  • 75
  • 79
Kaarel
  • 10,554
  • 4
  • 56
  • 78
  • "but rather specifying the wish for the Sharesheet as an ACTION and/or EXTRA" -- that is [what `createChooser()` does](https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:frameworks/base/core/java/android/content/Intent.java;l=1016-1050). – CommonsWare Jan 01 '21 at 21:01
  • Thanks @CommonsWare. I realize now that my question was more about how to open a sheet with frequent contacts and SEND-apps without having to create an intent that embeds another intent, something like `ACTION_SEND_WITH_CHOOSER`. I guess such a flat intent for this purpose does not exist. – Kaarel Jan 04 '21 at 09:59
  • "I guess such a flat intent for this purpose does not exist" -- AFAIK, `ACTION_SEND` alone should bring up the share sheet. The primary point behind the "chooser" stuff is to *force* such a sheet. The user might have set up a default `ACTION_SEND` behavior, just as they might have set up a default Web browser or default messaging client for `Intent` actions for viewing Web pages or sending messages. With such a default, the share sheet would be bypassed. The chooser effectively "breaks" any such default and forces the share sheet to appear. – CommonsWare Jan 04 '21 at 12:00

0 Answers0