在移动版android中打开google play商店的链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10922762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:29:43  来源:igfitidea点击:

open link of google play store in mobile version android

androidgoogle-play

提问by ghostrider

I have link of my other apps in my latest app, and I open them in that way.

我在最新的应用程序中有其他应用程序的链接,我以这种方式打开它们。

Uri uri = Uri.parse("url");
Intent intent = new Intent (Intent.ACTION_VIEW, uri); 
startActivity(intent);

this codes opens the browser version of google play store.

此代码打开谷歌播放商店的浏览器版本。

When trying to open from my phone, the phone prompts if I want to use a browser or google play and if I choose the second one it opens the mobile version of google play store.

尝试从手机打开时,手机会提示我是要使用浏览器还是 google play,如果我选择第二个,它会打开 google play 商店的移动版本。

Can you tell me how can this happen at once? I mean not ask me but directly open the mobile version of google play, the one that I see while open it directly from phone.

你能告诉我这怎么会一下子发生?我的意思是不要问我,而是直接打开手机版的google play,我在手机上直接打开时看到的那个。

回答by Eric

You'll want to use the specified marketprotocol:

您将要使用指定的market协议:

final String appPackageName = "com.example"; // Can also use getPackageName(), as below
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));

Keep in mind, this will crash on any device that does not have the Market installed (the emulator, for example). Hence, I would suggest something like:

请记住,这将在任何未安装 Market 的设备(例如模拟器)上崩溃。因此,我建议如下:

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}

While using getPackageName()from Contextor subclass thereof for consistency (thanks @cprcrack!). You can find more on Market Intents here: link.

在使用getPackageName()fromContext或其子类以保持一致性时(感谢@cprcrack!)。您可以在此处找到有关市场意图的更多信息:链接

回答by Chirag Ghori

Below code may helps you for display application link of google play sore in mobile version.

下面的代码可以帮助您在移动版本中显示 google play sore 的应用程序链接。

For Application link :

申请链接:

Uri uri = Uri.parse("market://details?id=" + mContext.getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);

  try {
        startActivity(myAppLinkToMarket);

      } catch (ActivityNotFoundException e) {

        //the device hasn't installed Google Play
        Toast.makeText(Setting.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show();
              }

For Developer link :

对于开发人员链接:

Uri uri = Uri.parse("market://search?q=pub:" + YourDeveloperName);
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);

            try {

                startActivity(myAppLinkToMarket);

            } catch (ActivityNotFoundException e) {

                //the device hasn't installed Google Play
                Toast.makeText(Settings.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show();

            } 

回答by Dmitriy Tarasov

You can use Android Intentslibrary for opening your application page at Google Play like that:

您可以使用Android Intents库在 Google Play 中打开您的应用程序页面,如下所示:

Intent intent = IntentUtils.openPlayStore(getApplicationContext());
startActivity(intent);

回答by Paolo Rovelli

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

您可以检查是否安装了Google Play Store应用程序,如果是这种情况,您可以使用“market://”协议。

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);

回答by Paolo Rovelli

Open app page on Google Play:

在 Google Play 上打开应用页面:

Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=" + context.getPackageName()));
startActivity(intent);