このガイドでは、Kotlin または Java を使用して、アプリ内レビューをアプリに統合する方法について説明します。ネイティブ コード、Unity、Unreal Engine を使用している場合の統合ガイドは個別に用意されています。
開発環境を設定する
Play In-App Review Library は Google Play Core Library の一部です。Play In-App Review Library を統合するには、次の Gradle 依存関係を含めてください。
Groovy
// In your app's build.gradle file: ... dependencies { // This dependency is downloaded from the Google's Maven repository. // So, make sure you also include that repository in your project's build.gradle file. implementation 'com.google.android.play:review:2.0.2' // For Kotlin users also add the Kotlin extensions library for Play In-App Review: implementation 'com.google.android.play:review-ktx:2.0.2' ... }
Kotlin
// In your app's build.gradle.kts file: ... dependencies { // This dependency is downloaded from the Google's Maven repository. // So, make sure you also include that repository in your project's build.gradle file. implementation("com.google.android.play:review:2.0.2") // For Kotlin users also import the Kotlin extensions library for Play In-App Review: implementation("com.google.android.play:review-ktx:2.0.2") ... }
ReviewManager を作成する
ReviewManager は、アプリがアプリ内レビューフローを開始するためのインターフェースです。ReviewManagerFactory を使用してインスタンスを作成することにより取得します。
Kotlin
val manager = ReviewManagerFactory.create(context)
Java
ReviewManager manager = ReviewManagerFactory.create(context)
ReviewInfo オブジェクトをリクエストする
アプリ内レビューをリクエストするタイミングのガイダンスに沿って、アプリのユーザーフロー内で、ユーザーにレビューを依頼するのに適切なポイント(ゲームでレベルをクリアしたときなど)を見つけます。アプリがそのポイントに到達したら、ReviewManager インスタンスを使用してリクエスト タスクを作成します。成功すると、アプリ内レビューフローの開始に必要な ReviewInfo オブジェクトが API から返されます。
Kotlin
val request = manager.requestReviewFlow()
request.addOnCompleteListener { task ->
if (task.isSuccessful) {
// Got the ReviewInfo object
val reviewInfo = task.result
} else {
// There was some problem, log or handle the error code.
@ReviewErrorCode val reviewErrorCode = (task.getException() as ReviewException).errorCode
}
}
Java
ReviewManager manager = ReviewManagerFactory.create(this);
Task<ReviewInfo> request = manager.requestReviewFlow();
request.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
// Get the ReviewInfo object
ReviewInfo reviewInfo = task.getResult();
} else {
// There was some problem, log or handle the error code.
@ReviewErrorCode int reviewErrorCode = ((ReviewException) task.getException()).getErrorCode();
}
});
アプリ内レビューフローを開始する
ReviewInfo インスタンスを使用して、アプリ内レビューフローを開始します。アプリ内レビューフローが完了するのを待ってから、通常のユーザーフロー(次のレベルに進むなど)を再開します。
Kotlin
val flow = manager.launchReviewFlow(activity, reviewInfo)
flow.addOnCompleteListener { _ ->
// The flow has finished. The API doesn't indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, continue your app flow.
}
Java
Task<Void> flow = manager.launchReviewFlow(activity, reviewInfo);
flow.addOnCompleteListener(task -> {
// The flow has finished. The API doesn't indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, continue your app flow.
});
次のステップ
アプリのアプリ内レビューフローをテストして、統合が正しく機能していることを検証します。