Skip to content

Instantly share code, notes, and snippets.

@yaraki
Created June 12, 2023 09:45
Show Gist options
  • Save yaraki/af7580cf6f8036a7e79b69c7941df483 to your computer and use it in GitHub Desktop.
Save yaraki/af7580cf6f8036a7e79b69c7941df483 to your computer and use it in GitHub Desktop.
val sendIntent = Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_TEXT, text)
val shareIntent = Intent.createChooser(sendIntent, null)
val customActions = arrayOf(
ChooserAction.Builder(
Icon.createWithResource(context, R.drawable.ic_send_to_devices),
"Send to your devices",
PendingIntent.getBroadcast(
context,
1,
sendIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_CANCEL_CURRENT
)
).build()
)
shareIntent.putExtra(Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS, customActions)
context.startActivity(shareIntent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment