谷歌Play商店的移动版Android开放链接商店、链接、谷歌、Play

2023-09-11 11:49:44 作者:青春别挥霍

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

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

这codeS打开谷歌Play商店的浏览器版本。

this codes opens the browser version of google play store.

当试图从我的手机打开时,手机会提示,如果我想使用一个浏览器或谷歌播放,如果我选择第二个它会打开谷歌移动版本的Play商店。

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.

您可以告诉我怎么能这样一次?我的意思是不要问我,而是直接打开谷歌游戏的移动版本,一个,我看到时打开它直接从手机上。

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.

推荐答案

您需要使用指定的市场协议:

You'll want to use the specified market protocol:

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:

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()从上下文或其子类的一致性(感谢 @cprcrack !) 。你可以在这里找到更多的市场意图: link.

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