Android Share Text or Url Intent

June 17, 2018
val url = "https://www.travelopy.com"

ShareCompat.IntentBuilder
        .from(activity)
        .setType("text/plain")
        .setChooserTitle("Share URL")
        .setText(url)
        .startChooser()

NOTE: Will always show chooser dialog even default app is selected.

or

val shareIntent = ShareCompat.IntentBuilder
        .from(activity)
        .setType("text/plain")
        .setChooserTitle("Share URL")
        .setText(url)
        .intent

if (shareIntent.resolveActivity(activity.packageManager) != null) {
    activity.startActivity(shareIntent)
}

NOTE: Will not show chooser dialog if default app is selected.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.