-1

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.

8
  • What does it mean by But it not redirected to play store directly? "directly"? Then how does it go if not directly? Commented May 23, 2022 at 15:07
  • @Sambhav.K I want to redirect to my app in play store. means after click on button then firstly not open any browser and any third party app. i want to open play store directly and inside play store my app page open. So are you understand the actual problem. Commented May 24, 2022 at 4:35
  • Ok. I get it now. You also can edit your post saying that the browser opens first and then it happens. BTW I also added the answer for it Commented May 24, 2022 at 5:59
  • @Sambhav.K I edited . Commented May 25, 2022 at 4:40
  • Did you check my answer? Commented May 25, 2022 at 4:41

5 Answers 5

3

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..

Sign up to request clarification or add additional context in comments.

Comments

1

This worked for me...

private fun goToAppStore() {
    val sendIntent = Intent()
    sendIntent.action = Intent.ACTION_VIEW
    sendIntent.data = Uri.parse("market://details?id=$YOUR_PACKAGE_NAME")
    if(sendIntent.resolveActivity(packageManager) != null) {
        startActivity(sendIntent)
    }
}

Comments

1

The currently correct approach for creating a link to Google Play out of an Android app is described in the Google Play developer documentation (including a piece of code): https://developer.android.com/distribute/marketing-tools/linking-to-google-play#android-app

In order to handle the case that Google Play is not installed on the respective device, you can add a try/catch statement that opens the Google Play URL in the browser.

Comments

0

You have done it right but, you missed out a thing. You haven't set the package for it to open in. So, instead try this code:

fun shareApp(message : String, activity: Activity){
    val sendIntent = Intent()
    sendIntent.action = Intent.ACTION_SEND
    sendIntent.package = "com.android.vending" // this is the line you missed
    sendIntent.putExtra(
        Intent.EXTRA_TEXT,
        message
    )
    sendIntent.type = "text/plain"
    activity.startActivity(sendIntent)
}

1 Comment

Got error and app crashed ,showing error log :- android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/plain flg=0x1 pkg=com.android.vending clip={text/plain T:play.google.com/store/apps/details?id=app.suraj.myApp} (has extras) }
0

In case useful to someone, I use this in composable function screen to open the app page on Google Play Store from inside the app itself :

    private fun goToGooglePLayStore(context: Context) {
    try {
        startActivity(context,
            Intent(Intent.ACTION_VIEW, Uri.parse(
                "market://details?id=$GOOGLE_PLAY_STORE_PACKAGE_NAME")),
        null)
    } catch (e: ActivityNotFoundException) {
        startActivity(context,
            Intent(Intent.ACTION_VIEW, Uri.parse(
                "https://play.google.com/store/apps/details?id=" +
                        "$GOOGLE_PLAY_STORE_PACKAGE_NAME")),
            null
        )
    }
}

where GOOGLE_PLAY_STORE_PACKAGE_NAME = {you app package name}

context: activity context passed from composable function with :

val context = LocalContext.current

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.