인앱 리뷰 통합(Kotlin 또는 자바)

이 가이드에서는 Kotlin 또는 자바를 사용하여 앱에 인앱 리뷰를 통합하는 방법을 설명합니다. 네이티브 코드 또는 Unity를 사용한다면 별도의 통합 가이드를 참고하세요.

개발 환경 설정

Play In-App Review 라이브러리는 Google Play Core 라이브러리의 일부입니다. Play In-App Review 라이브러리를 통합하려면 다음 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.1'

    // For Kotlin users also add the Kotlin extensions library for Play In-App Review:
    implementation 'com.google.android.play:review-ktx:2.0.1'
    ...
}

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.1")

    // For Kotlin users also import the Kotlin extensions library for Play In-App Review:
    implementation("com.google.android.play:review-ktx:2.0.1")
    ...
}

ReviewManager 생성

ReviewManager는 앱에서 인앱 리뷰 흐름을 시작할 수 있는 인터페이스입니다. ReviewManagerFactory를 사용해 인스턴스를 생성하여 가져올 수 있습니다.

Kotlin

val manager = ReviewManagerFactory.create(context)

Java

ReviewManager manager = ReviewManagerFactory.create(context)

ReviewInfo 객체 요청

인앱 리뷰를 요청하는 경우에 관한 가이드라인에 따라 앱의 사용자 플로우에서 적절한 지점을 결정하여 사용자에게 리뷰를 요청하는 메시지를 표시합니다(예를 들어 게임에서 사용자가 레벨을 완료할 때). 앱은 이러한 지점 중 하나에 도달하면 ReviewManager 인스턴스를 사용하여 요청 작업을 생성합니다. 성공하면 API는 인앱 리뷰 흐름을 시작하는 데 필요한 ReviewInfo 객체를 반환합니다.

Kotlin

val request = manager.requestReviewFlow()
request.addOnCompleteListener { task ->
    if (task.isSuccessful) {
        // We 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()) {
        // We can 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 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.
}

Java

Task<Void> flow = manager.launchReviewFlow(activity, reviewInfo);
flow.addOnCompleteListener(task -> {
    // 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.
});

다음 단계

앱의 인앱 검토 흐름 테스트를 통해 통합이 제대로 작동하는지 확인합니다.