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

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

    You can check if the Google Play Store app is installed and, if this is the case, you can use the "market://" protocol.

    final String my_package_name = "........."  // <- HERE YOUR PACKAGE NAME!!
    String url = "";
    
    try {
        //Check whether Google Play store is installed or not:
        this.getPackageManager().getPackageInfo("com.android.vending", 0);
    
        url = "market://details?id=" + my_package_name;
    } catch ( final Exception e ) {
        url = "https://play.google.com/store/apps/details?id=" + my_package_name;
    }
    
    
    //Open the app page in Google Play store:
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    startActivity(intent);
    

提交回复
热议问题