在
@Composable
内,您可以以标准方式使用
Intent
。
类似:
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")
}
在 Jetpack compose Sharesheet 中,您可以通过在任何可组合函数中传递 context 来调用以下函数
fun shareAppPlayStoreUrl(context: Context){
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "Check out this awesome app\n "+"https://play.google.com/store/apps/details?id="+context.applicationInfo.packageName)
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)
context.startActivity(shareIntent)
}