Created
October 25, 2022 17:48
-
-
Save Astroa7m/8b746266cd4ef2d9b61c6678b5df5b74 to your computer and use it in GitHub Desktop.
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
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