В этом руководстве описано, как интегрировать отзывы в приложении с помощью 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) {
// 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.
});
Дальнейшие действия
Протестируйте процесс оставления отзыва в приложении, чтобы убедиться, что интеграция работает правильно.