Android初心者がAndroidアプリでGooglePlayを開こうとしてつまづいた話
Androidアプリ初心者なのですが、「このアプリをレビューする」みたいなボタンの開発を任され、アプリ内でGooglePlayを開こうと思った。
もろもろ調べて以下のような記事を発見
techbooster.jpn.org
なるほど
Uri uri = Uri.parse("market://details?id=com.hogehoge.piyopiyo"); Intent intent = new Intent(Intent.ACTION_VIEW,uri); startActivity(intent);
みたいな感じで呼べばいいのね。と思い実装してみると
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.hogehoge.piyopiyo
というエラー。よくわからん…と思いさらに検索するとstackoverflow様が
You are running this code on an Android environment that lacks the Google Play Store, such as an emulator, Kindle Fire, etc.
エミュレータとかKindleFireみたいにGooglePlayStoreのない端末でやってるからエラってるよ。みたいな。
なるほど。で、もろもろ調べた結果、
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.hogehoge.piyopiyo”);
みたいな書き方すると、GooglePlayStoreがあればPlayStore、なければブラウザが立ち上がってくれるっぽく、変な例外処理も書かなくていいことに気づき事なきを得た。
なるほど。