Skip to content

Instantly share code, notes, and snippets.

@5AbhishekSaxena
Last active December 14, 2021 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5AbhishekSaxena/408a7a22497d8b71e121a4d683f974f7 to your computer and use it in GitHub Desktop.
Save 5AbhishekSaxena/408a7a22497d8b71e121a4d683f974f7 to your computer and use it in GitHub Desktop.
Method 1 for sharing text intent
fun shareSimpleText(context: Context, text: String) {
val intent = ShareCompat.IntentBuilder(context)
.setType("text/plain")
.setText(text)
.intent
val intentWithChooser = Intent.createChooser(intent, "Sharing with")
context.startActivity(intentWithChooser)
}
fun shareViaSms(context: Context, sms: Sms) {
val intent = Intent().apply {
action = Intent.ACTION_VIEW
data = Uri.parse("sms: ${sms.phoneNumber}")
putExtra("sms_body", sms.body)
}
val intentWithChooser = Intent.createChooser(intent, "Sharing with")
context.startActivity(intentWithChooser)
}
fun openWebPage(context: Context, url: String) {
val intent = Intent().apply {
action = Intent.ACTION_VIEW
data = url.toUri()
}
val intentWithChooser = Intent.createChooser(intent, "Open url using")
context.startActivity(intentWithChooser)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment