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

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

    use market://

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + my_packagename));
    
    0 讨论(0)
  • 2020-11-22 02:09

    Kotlin

    fun openAppInPlayStore(appPackageName: String) {
        try {
            startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appPackageName")))
        } catch (exception: android.content.ActivityNotFoundException) {
            startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")))
        }
    }
    
    0 讨论(0)
  • 2020-11-22 02:11

    Very late in the party Official docs are here. And code described is

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(
        "https://play.google.com/store/apps/details?id=com.example.android"));
    intent.setPackage("com.android.vending");
    startActivity(intent);
    

    As you configure this intent, pass "com.android.vending" into Intent.setPackage() so that users see your app's details in the Google Play Store app instead of a chooser. for KOTLIN

    val intent = Intent(Intent.ACTION_VIEW).apply {
        data = Uri.parse(
                "https://play.google.com/store/apps/details?id=com.example.android")
        setPackage("com.android.vending")
    }
    startActivity(intent)
    

    If you have published an instant app using Google Play Instant, you can launch the app as follows:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri.Builder uriBuilder = Uri.parse("https://play.google.com/store/apps/details")
        .buildUpon()
        .appendQueryParameter("id", "com.example.android")
        .appendQueryParameter("launch", "true");
    
    // Optional parameters, such as referrer, are passed onto the launched
    // instant app. You can retrieve these parameters using
    // Activity.getIntent().getData().
    uriBuilder.appendQueryParameter("referrer", "exampleCampaignId");
    
    intent.setData(uriBuilder.build());
    intent.setPackage("com.android.vending");
    startActivity(intent);
    

    For KOTLIN

    val uriBuilder = Uri.parse("https://play.google.com/store/apps/details")
            .buildUpon()
            .appendQueryParameter("id", "com.example.android")
            .appendQueryParameter("launch", "true")
    
    // Optional parameters, such as referrer, are passed onto the launched
    // instant app. You can retrieve these parameters using Activity.intent.data.
    uriBuilder.appendQueryParameter("referrer", "exampleCampaignId")
    
    val intent = Intent(Intent.ACTION_VIEW).apply {
        data = uriBuilder.build()
        setPackage("com.android.vending")
    }
    startActivity(intent)
    
    0 讨论(0)
  • 2020-11-22 02:14

    try this

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("market://details?id=com.example.android"));
    startActivity(intent);
    
    0 讨论(0)
  • 2020-11-22 02:14

    As the official docs use https:// instead of market://, this combines Eric's and M3-n50's answer with code reuse (don't repeat yourself):

    Intent intent = new Intent(Intent.ACTION_VIEW)
        .setData(Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
    try {
        startActivity(new Intent(intent)
                      .setPackage("com.android.vending"));
    } catch (android.content.ActivityNotFoundException exception) {
        startActivity(intent);
    }
    

    It tries to open with the GPlay app if it exists and falls back to default.

    0 讨论(0)
  • 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)));
            }
        }
    
    0 讨论(0)
提交回复
热议问题