В этом руководстве описывается, как интегрировать обзоры в приложении с помощью Kotlin или Java. Существуют отдельные руководства по интеграции, если вы используете нативный код , Unity или Unreal Engine .
Настройте среду разработки
Библиотека обзора Play In-App является частью библиотек Google Play Core . Включите следующую зависимость Gradle для интеграции библиотеки обзора Play In-App.
Круто
// 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' ... }
Котлин
// 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
.
Котлин
val manager = ReviewManagerFactory.create(context)
Ява
ReviewManager manager = ReviewManagerFactory.create(context)
Запросить объект ReviewInfo
Следуйте указаниям о том, когда запрашивать отзывы в приложении , чтобы определить хорошие моменты в потоке пользователя вашего приложения, чтобы побудить пользователя оставить отзыв (например, когда пользователь завершает уровень в игре). Когда ваше приложение достигает одной из этих точек, используйте экземпляр ReviewManager
для создания задачи запроса. В случае успеха API возвращает объект ReviewInfo
, необходимый для запуска потока отзывов в приложении.
Котлин
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 } }
Ява
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
для запуска потока обзора в приложении. Подождите, пока пользователь не завершит поток обзора в приложении, прежде чем ваше приложение продолжит свой обычный поток пользователя (например, перейдет на следующий уровень).
Котлин
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. }
Ява
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. });
Следующие шаги
Протестируйте процесс проверки вашего приложения, чтобы убедиться, что интеграция работает правильно.