Sharesheet in Jetpack Compose

Total
10
Shares

How do I share content using Android’s Sharesheet in Jetpack Compose?

enter image description here


Solution

Inside a @Composable you can use an Intent in a standard way.

Something like:

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)
val context = LocalContext.current

Button(onClick = {
    context.startActivity(shareIntent)
}){
    Text("Share")
}

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *