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

后端 未结 23 2772
既然无缘
既然无缘 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:19

    Here is the final code from the answers above that first attempts to open the app using the Google play store app and specifically play store, if it fails, it will start the action view using the web version: Credits to @Eric, @Jonathan Caballero

    public void goToPlayStore() {
            String playStoreMarketUrl = "market://details?id=";
            String playStoreWebUrl = "https://play.google.com/store/apps/details?id=";
            String packageName = getActivity().getPackageName();
            try {
                Intent intent =  getActivity()
                                .getPackageManager()
                                .getLaunchIntentForPackage("com.android.vending");
                if (intent != null) {
                    ComponentName androidComponent = new ComponentName("com.android.vending",
                            "com.google.android.finsky.activities.LaunchUrlHandlerActivity");
                    intent.setComponent(androidComponent);
                    intent.setData(Uri.parse(playStoreMarketUrl + packageName));
                } else {
                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreMarketUrl + packageName));
                }
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreWebUrl + packageName));
                startActivity(intent);
            }
        }
    

提交回复
热议问题