android - 在手机版android中打开google play store的链接

标签 android google-play

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

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,就是我手机直接打开看到的那个。

最佳答案

您需要使用指定的 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 的设备(例如模拟器)上崩溃。因此,我建议如下:

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 !)。您可以在此处找到有关市场 Intent 的更多信息: link

关于android - 在手机版android中打开google play store的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10922762/

相关文章:

android - Zbar 集成到 Android 应用程序中

android - Google Play 权限声明表单无法访问

android - 如何禁用Android Studio代码风格警告 "... can be simplified to ..."

java - 我想在棉花糖android中发送Http请求?

android - 什么时候使用谷歌 "Application Licensing"?

android - Google Play 控制台显示自 5 月 7 日起所有应用中的数据不正确

android - 如何在自己的安卓手机上安装自己在安卓市场发布的付费应用?

android - Play Store 上发布的应用程序无法与 Google Maps API 和 Facebook API 通信

java - 在Android Studio中构建项目时出现Java.exe错误

android - jQuery 手机 : page transitions cannot be set to none on Android