在手机版android中打开google play store的链接 [英] open link of google play store in mobile version android

查看:106
本文介绍了在手机版android中打开google play store的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

this codes opens the browser version of google play store.

当我尝试从我的手机打开时,手机会提示我是要使用浏览器还是 google play,如果我选择第二个,它会打开手机版的 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,我直接从手机打开看到的那个.

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.

推荐答案

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

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

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

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() 来自 Context 或其子类以保持一致性(感谢 @cprcrack!).您可以在此处找到有关市场意图的更多信息:链接.

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

这篇关于在手机版android中打开google play store的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆