В этом руководстве описано, как интегрировать отзывы в приложение с помощью Kotlin или Java. Если вы используете нативный код, Unity или Unreal Engine, ознакомьтесь с отдельными руководствами по интеграции.
Как настроить среду разработки
Play In-App Review Library – это часть библиотек Google Play Core. Чтобы интегрировать библиотеку Play In-App Review, добавьте следующую зависимость Gradle:
Яркий
// 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, чтобы создать задачу запроса. Если все в порядке, 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. });
Дальнейшие действия
Протестируйте процесс оставления отзыва в приложении, чтобы убедиться, что интеграция работает правильно.