Este guia descreve como integrar avaliações no app usando Kotlin ou Java. Há guias de integração separados se você estiver usando código nativo, Unity ou Unreal Engine.
Configurar o ambiente de desenvolvimento
A Biblioteca Play In-App Review faz parte das Bibliotecas Google Play Core. Inclua a dependência do Gradle abaixo para integrar a biblioteca Play In-App Review.
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") ... }
Criar o ReviewManager
O ReviewManager é a interface que permite ao app iniciar um fluxo de avaliação no app. Ele pode ser acessado criando uma instância usando o
ReviewManagerFactory.
Kotlin
val manager = ReviewManagerFactory.create(context)
Java
ReviewManager manager = ReviewManagerFactory.create(context)
Solicitar um objeto ReviewInfo
Siga as orientações sobre quando solicitar avaliações no app para determinar bons pontos no fluxo do usuário (por exemplo, quando o usuário conclui um nível em um jogo). Quando o app atingir um desses pontos, use a instância ReviewManager para criar uma tarefa de solicitação. Se for bem-sucedida, a API vai retornar o objeto ReviewInfo necessário para iniciar o fluxo de avaliação no app.
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();
}
});
Iniciar o fluxo de avaliação no app
Use a instância ReviewInfo para iniciar o fluxo de avaliação no app. Aguarde o usuário concluir o
fluxo de avaliação antes de continuar com o fluxo normal de usuários (como
avançar para o próximo nível).
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.
});
Próximas etapas
Teste o fluxo de avaliações no app para verificar se a integração está funcionando corretamente.