How to open the Google Play Store directly from my Android application?

后端 未结 23 2725
既然无缘
既然无缘 2020-11-22 02:00

I have open the Google Play store using the following code

Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse(\"https://play.goo         


        
23条回答
  •  旧巷少年郎
    2020-11-22 02:25

    Some of the answers to this question are outdated.

    What worked for me (in 2020) was to explicitly tell the intent to skip the chooser and directly open the play store app, according to this link:

    "If you want to link to your products from an Android app, create an Intent that opens a URL. As you configure this intent, pass "com.android.vending" into Intent.setPackage() so that users see your app's details in the Google Play Store app instead of a chooser."

    This is the Kotlin code I used to direct users to viewing the app containing the package name com.google.android.apps.maps in Google Play:

    val intent = Intent(Intent.ACTION_VIEW).apply {
                   data = Uri.parse("http://play.google.com/store/apps/details?id=com.google.android.apps.maps")
                   setPackage("com.android.vending")
                }
                startActivity(intent)
    

    I hope that helps someone!

提交回复
热议问题