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

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

    Ready-to-use solution:

    public class GoogleServicesUtils {
    
        public static void openAppInGooglePlay(Context context) {
            final String appPackageName = context.getPackageName();
            try {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
            } catch (android.content.ActivityNotFoundException e) { // if there is no Google Play on device
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
            }
        }
    
    }
    

    Based on Eric's answer.

提交回复
热议问题