androidkotlinandroid-jetpackandroid-jetpack-compose

Sharesheet in Jetpack Compose


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