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

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

    public void launchPlayStore(Context context, String packageName) {
        Intent intent = null;
        try {
                intent = new Intent(Intent.ACTION_VIEW);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setData(Uri.parse("market://details?id=" + packageName));
                context.startActivity(intent);
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
            }
        }
    

提交回复
热议问题