6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Android】Google Play Storeアプリで任意のアプリや検索結果を開く

Last updated at Posted at 2017-08-23

AndroidアプリからPlay Storeアプリの自分自身のアプリページやパブリッシャーページを開きたかったので調べてみました。

アプリページを開く

fun openPlayStore(context: Context, packageName: String) {
    val url: String = "market://details?id=$packageName"
    val intent = Intent(Intent.ACTION_VIEW)
    intent.data = Uri.parse(url)
    try {
        context.startActivity(intent)
    } catch (e: ActivityNotFoundException) {
        intent.data = Uri.parse("https://play.google.com/store/apps/details?id=$packageName")
        context.startActivity(intent)
    }
}

ActivityNotFoundException発生時はブラウザのPlay Storeを開きます。

検索結果ページを開く

fun openPlayStore(context: Context, query: String) {
    val url: String = "market://search?q=$query"
    val intent = Intent(Intent.ACTION_VIEW)
    intent.data = Uri.parse(url)
    try {
        context.startActivity(intent)
    } catch (e: ActivityNotFoundException) {
        intent.data = Uri.parse("https://play.google.com/store/search?q=${query}&c=apps")
        context.startActivity(intent)
    }
}

market://search?q=$queryのところをmarket://search?q=pub:<パブリッシャー名>とすることで特定のパブリッシャーの検索結果を開くこともできます。

例)market://search?q=pub:Google

補足

他にもデベロッパーページやコレクション(無料トップ、有料トップなど)へもリンクさせることができるらしいです。

まとめ

Result Web page link Android app link
Detail http://play.google.com/store/apps/details?id=<package_name> market://details?id=<package_name>
Dev https://play.google.com/store/apps/dev?id=<developer_id> market://dev?id=<developer_id>
Search http://play.google.com/store/search?q=<query> market://search?q=<query>
Collection http://play.google.com/store/apps/collection/<collection_name> market://apps/collection/<collection_name>

詳しくは [Linking to Google Play | Android Developers]
(https://developer.android.com/distribute/marketing-tools/linking-to-google-play.html) を参照してください。

参考

Linking to Google Play | Android Developers
https://developer.android.com/distribute/marketing-tools/linking-to-google-play.html

How to open the Google Play Store directly from my Android application? - Stack Overflow
https://stackoverflow.com/questions/11753000/how-to-open-the-google-play-store-directly-from-my-android-application

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?