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

时间:2012-06-06 21:45:40

标签: android google-play

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

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

此代码会打开Goog​​le Play商店的浏览器版本。

尝试从手机打开时,手机会提示我是否要使用浏览器或Google Play,如果我选择第二个,则会打开移动版Google Play商店。

你能告诉我这怎么可能一下子发生?我的意思是不要问我,而是直接打开谷歌播放的移动版本,这是我在手机直接打开时看到的版本。

6 个答案:

答案 0 :(得分:264)

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

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

答案 1 :(得分:6)

下面的代码可以帮助您在移动版本中显示谷歌游戏疮的应用程序链接。

对于应用程序链接:

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

            } 

答案 2 :(得分:3)

您可以使用Android Intents库在Google Play上打开您的应用程序页面:

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

答案 3 :(得分:1)

答案 4 :(得分:1)

您可以检查是否安装了 Google Play商店应用,如果是这种情况,您可以使用“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);

答案 5 :(得分:0)

在Google Play上打开应用页面:

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