[Android] How to open the Google Play Store directly from my Android application?

Posted in :

如果是在Android app 裡寫code, 可以使用:

You can do this using the market:// prefix.

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.

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

 

如果是使用 html link 參考看看這篇:

Android Intents with Chrome
http://stackoverflow.max-everyday.com/2017/03/android-intents-with-chrome/

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *