Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

android - 如何直接从我的Android应用程序打开Goog??le Play商店?(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商店中打开应用程序。)

  ask by Rajesh Kumar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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答案)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...