🐴
【Android】In-App Review APIを使ってレビュー機能を実装する【KMP】
はじめに
こんにちは、Haruです。
以下の様なレビュー画面の実装を行います。
引用:Google Play In-App Review API | Other Play guides | Android Developers
※なお、Compose Multiplatformではありますが、iOSはまだ実装していません。
今後実装次第、こちらも更新するかもしれませんし、しないかもしれません。
ご了承ください。
実装方法
- build.gradle.kts
implementation("com.google.android.play:review:2.0.2")
implementation("com.google.android.play:review-ktx:2.0.2")
- commonMain
expect fun requestReview()
- androidMain
actual fun requestReview() {
val context = PlatformContextProvider.context
val activity = context as? Activity ?: return
val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { task ->
if (task.isSuccessful) {
// We got the ReviewInfo object
val reviewInfo = task.result
val flow = manager.launchReviewFlow(activity, reviewInfo)
flow.addOnCompleteListener { _ ->
// The flow has finished. The API does not indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, we continue our app flow.
}
} else {
// There was some problem, log or handle the error code.
@ReviewErrorCode val reviewErrorCode = (task.getException() as ReviewException).errorCode
Log.e("InAppReview", "Review task failed with error code: $reviewErrorCode", task.exception)
}
}
}
- iosMain
actual fun requestReview() {
// iOS 版は未実装のためダミー実装
// (SKStoreReviewController は今回は扱わない)
println("iOS requestReview called (dummy implementation)")
}
上記のように実装したら、以下の様な感じで呼び出しできます。
Button(
onClick = { requestReview() }
) {
Text("アプリを評価する")
}
※ In-App Review は必ず表示されるわけではなく、表示可否は Google Play 側で制御されます。
テスト
動作確認は、Google Play Consoleにアプリをアップロードし、内部テストで動作確認しましょう!
以下のように表示されていたらOKです。
内部テストであれば、実際にレビュー送信もできます。非公開なので、安心してテストできます。

※ In-App Review ダイアログの表示例(開発中アプリでの表示例)
参考
アプリ内レビューを統合する(Kotlin または Java) | Other Play guides | Android Developers
【Android】In-App Review APIを使ってレビュー機能をサクッと作ろう #Kotlin - Qiita
Google Play In-App Review API実装まとめ - アイリッジ開発者ブログ

Discussion