我的最新应用中有其他应用的链接,我以这种方式打开它们。
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/