-
-
Save 5AbhishekSaxena/408a7a22497d8b71e121a4d683f974f7 to your computer and use it in GitHub Desktop.
Method 1 for sharing text intent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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