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

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

    You can do this using the market:// prefix.

    final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
    try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
    } catch (android.content.ActivityNotFoundException anfe) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
    }
    

    We use a try/catch block here because an Exception will be thrown if the Play Store is not installed on the target device.

    NOTE: any app can register as capable of handling the market://details?id= Uri, if you want to specifically target Google Play check the Berťák answer

提交回复
热议问题