如何直接从我的Android应用程序打开Goog​​le Play商店?

本文探讨了如何在Android应用中直接打开Google Play商店,避免出现选择浏览器或Play商店的选项。建议使用特定的Uri前缀,如"market://",并注意可能需要检查Play商店是否已安装在目标设备上。还提到了通过判断协议来实现打开Play商店的方案。
摘要由CSDN通过智能技术生成

本文翻译自:How to open the Google Play Store directly from my Android application?

I have open the Google Play store using the following code 我已使用以下代码打开Goog​​le Play商店

Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=my packagename "));
startActivity(i);.

But it shows me a Complete Action View as to select the option (browser/play store). 但它显示了一个完整的动作视图,以选择选项(浏览器/播放商店)。 I need to open the application in Play Store directly. 我需要直接在Play商店中打开应用程序。


#1楼

参考:https://stackoom.com/question/nJUW/如何直接从我的Android应用程序打开Goog-le-Play商店


#2楼

You can do this using the market:// prefix . 您可以使用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("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

We use a try/catch block here because an Exception will be thrown if the Play Store is not installed on the target device. 我们使用try/catch这里块,因为Exception将被抛出,如果Play商店未在目标设备上安装。

NOTE : any app can register as capable of handling the market://details?id=<appId> Uri, if you want to specifically target Google Play check the Berťák answer 注意 :任何应用都可以注册为能够处理market://details?id=<appId> Uri,如果您想专门针对Google Play检查Berťák答案


#3楼

使用市场://

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

#4楼

You can do: 你可以做:

final Uri marketUri = Uri.parse("market://details?id=" + packageName);
startActivity(new Intent(Intent.ACTION_VIEW, marketUri));

get Reference here : 在这里得到参考:

You can also try the approach described in the accepted answer of this question: Cannot determine whether Google play store is installed or not on Android device 您还可以尝试此问题的接受答案中描述的方法: 无法确定Android设备上是否安装了Google Play商店


#5楼

try this 试试这个

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);

#6楼

You can check if the Google Play Store app is installed and, if this is the case, you can use the "market://" protocol. 您可以检查是否已安装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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值