【问题标题】:open link of google play store in mobile version android在手机版android中打开google play store的链接
【发布时间】:2012-06-10 23:21:34
【问题描述】:

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

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

此代码将打开 google play store 的浏览器版本。

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

你能告诉我这怎么会立即发生?我的意思是不问我,直接打开手机版的google play,就是我手机直接打开看到的那个。

【问题讨论】:

  • 我希望倒数第二段对我来说是正确的。使用此处找到的 http 链接:developer.android.com/distribute/googleplay/promote/… 不会提示用户选择应用程序或浏览器。它总是假定浏览器。不幸的是,我也不能使用market:// 协议。还有其他人看到这种行为吗?

标签: android google-play


【解决方案1】:

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

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

请注意,这将在任何未安装 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)));
}

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

【讨论】:

  • 在浏览器中打开以下内容不会打开 Google Play:market://details?id=pandora
  • ID是包名,不是app名。试试market://details?id=com.PandoraTV(假设this是你想要的应用)。
  • 这个答案是关于在您自己的应用程序中使用 market:// 前缀,而不是通过浏览器从网站中使用。我可以证明它的功能(在版本 2.3、3 .x、4.0、4.1 和 4.2),它适用于普通浏览器、Chrome Beta 25 和 Chrome 18。
  • 是的,Chrome 是一个应用程序,但这需要它的制造者 [Google] 使用此代码,而不是 [你] 制作网站的人。就目前而言,这段代码是为了帮助那些专门从他们的应用中构建链接的人。
  • 您可以使用getPackageName() 自动检索应用ID。
【解决方案2】:

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

申请链接:

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

对于开发者链接:

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

            } 

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

    • 请注意 link-only answers 是不鼓励的,所以答案应该是寻找解决方案的终点(与另一个中途停留的参考相比,随着时间的推移往往会变得陈旧)。请考虑在此处添加独立的概要,并保留链接作为参考。
    • 加入免责声明会很有帮助,即这是您的图书馆,the function is implemented 与接受的答案几乎相同。
    【解决方案4】:
    【解决方案5】:

    您可以检查是否安装了 Google Play Store 应用,如果是这样,您可以使用 "market://" 协议。 p>

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

    【讨论】:

      【解决方案6】:

      在 Google Play 上打开应用页面:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多