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

后端 未结 23 3118
既然无缘
既然无缘 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:14

    As the official docs use https:// instead of market://, this combines Eric's and M3-n50's answer with code reuse (don't repeat yourself):

    Intent intent = new Intent(Intent.ACTION_VIEW)
        .setData(Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
    try {
        startActivity(new Intent(intent)
                      .setPackage("com.android.vending"));
    } catch (android.content.ActivityNotFoundException exception) {
        startActivity(intent);
    }
    

    It tries to open with the GPlay app if it exists and falls back to default.

提交回复
热议问题