Issue
I used below code to open directly google play store whenever click on share button.
Used Kotlin Extension
//Share apk
fun shareApp(message : String, activity: Activity){
val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.putExtra(
Intent.EXTRA_TEXT,
message
)
sendIntent.type = "text/plain"
activity.startActivity(sendIntent)
}
in fragment ->
shareApp("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID, requireActivity())
But it not redirected to play store directly , it redirected to browser and then open play store .
I want to open direct play store not from browser.
Solution
This solution is worked fine for me .
fun shareApp(appPackageName: String, activity: Activity){
try {
startActivity(Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$appPackageName")
))
} catch (e : ActivityNotFoundException) {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")
)
)
}
}
So here we use two things if any devices specific app store available then it open it and otherwise it open play store directly . and showing your app.
Whenever i click on button then it showing me choice for select market app or play store , when i click on play store then it open and show related app.
I hope this help you..
Answered By - Surajkaran Meghwanshi
Answer Checked By - Robin (JavaFixing Admin)