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

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

    Peoples, dont forget that you could actually get something more from it. I mean UTM tracking for example. https://developers.google.com/analytics/devguides/collection/android/v4/campaigns

    public static final String MODULE_ICON_PACK_FREE = "com.example.iconpack_free";
    public static final String APP_STORE_URI =
            "market://details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin";
    public static final String APP_STORE_GENERIC_URI =
            "https://play.google.com/store/apps/details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin";
    
    try {
        startActivity(new Intent(
            Intent.ACTION_VIEW,
            Uri.parse(String.format(Locale.US,
                APP_STORE_URI,
                MODULE_ICON_PACK_FREE,
                getPackageName()))).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
    } catch (android.content.ActivityNotFoundException anfe) {
        startActivity(new Intent(
            Intent.ACTION_VIEW,
            Uri.parse(String.format(Locale.US,
                APP_STORE_GENERIC_URI,
                MODULE_ICON_PACK_FREE,
                getPackageName()))).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
    }
    

提交回复
热议问题