Skip to content

Instantly share code, notes, and snippets.

@Astroa7m
Created October 25, 2022 17:48
Show Gist options
  • Save Astroa7m/8b746266cd4ef2d9b61c6678b5df5b74 to your computer and use it in GitHub Desktop.
Save Astroa7m/8b746266cd4ef2d9b61c6678b5df5b74 to your computer and use it in GitHub Desktop.
object SharingUtil {
private fun Context.createUserSharingUrl(id: Int): String {
val scheme = getString(R.string.scheme)
val host = getString(R.string.host)
val path = getString(R.string.path_to_existed_user)
return "$scheme://$host$path?userId=$id"
}
fun shareUserUrl(context: Context, user: User) {
val shareIntent = Intent(Intent.ACTION_SEND).apply {
//extra text -> text to be shared
putExtra(Intent.EXTRA_TEXT, context.createUserSharingUrl(user.id))
//extra title -> title to be previewed while sharing
putExtra(Intent.EXTRA_TITLE, "${user.name} | ${user.description}")
type = "text/plain"
}
val share = Intent.createChooser(shareIntent, null)
context.startActivity(share)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment