88

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

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

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

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

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

4

6 回答 6

265

您将要使用指定的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)));
}

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

于 2012-06-06T21:59:18.660 回答
6

下面的代码可以帮助您在移动版本中显示 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();

            } 
于 2013-09-12T07:19:36.770 回答
3

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

Intent intent = IntentUtils.openPlayStore(getApplicationContext());
startActivity(intent);
于 2013-08-20T08:28:40.873 回答
1

您可以检查是否安装了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);
于 2014-04-10T10:14:59.297 回答
0

在 Google Play 上打开应用页面:

Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=" + context.getPackageName()));
startActivity(intent);
于 2015-05-26T13:13:57.743 回答