ReviewManager manager = ReviewManagerFactory.create(this); Task request = manager.requestReviewFlow(); request.addOnCompleteListener ...
HowToAddGoogleIn-AppReviewforAndroidAndroidDevelopmentFebruary11,20222minutesVivekBeladiyaIntegratingin-appreviewsisveryeasy.Itcanbeachievedwithveryminimalcode.Let'sseehowtointegrateit.
1.AstheIn-AppReviewisapartofthePlaycorelibrary,weneedtoaddtherequireddependenciestoourapp'sbuild.gradle(applevel)file,
implementation“com.google.android.play:core:1.8.0”
implementation"com.google.android.material:material:1.3.0-alpha02"
2.First,weneedtocreatetheinstanceofReviewManagerwhichwouldhelpustostarttheAPI.Wecreatetheinstanceusing,
ReviewManagermanager=ReviewManagerFactory.create(this);
Now,usingthismanagerobject,wehavetorequesttheflowtolaunchtheIn-Appreviewflow.
ReviewManagermanager=ReviewManagerFactory.create(this);
Taskrequest=manager.requestReviewFlow();
request.addOnCompleteListener(task->{
if(task.isSuccessful()){
//WecangettheReviewInfoobject
ReviewInforeviewInfo=task.getResult();
}else{
//Therewassomeproblem,continueregardlessoftheresult.
}
});
Acompletecodeisrequiredforthein-appreviewflow.
MainActivity.java
importandroid.os.Bundle;
importandroidx.appcompat.app.AppCompatActivity;
importcom.google.android.material.dialog.MaterialAlertDialogBuilder;
importcom.google.android.play.core.review.ReviewInfo;
importcom.google.android.play.core.review.ReviewManager;
importcom.google.android.play.core.review.ReviewManagerFactory;
importcom.google.android.play.core.tasks.Task;
publicclassMainActivityextendsAppCompatActivity{
privateReviewManagerreviewManager;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
privatevoidinit(){
reviewManager=ReviewManagerFactory.create(this);
findViewById(R.id.btn_rate_app).setOnClickListener(view->showRateApp());
}
publicvoidshowRateApp(){
Taskrequest=reviewManager.requestReviewFlow();
request.addOnCompleteListener(task->{
if(task.isSuccessful()){
ReviewInforeviewInfo=task.getResult();
Taskflow=reviewManager.launchReviewFlow(this,reviewInfo);
flow.addOnCompleteListener(task1->{
});
}else{
showRateAppFallbackDialog();
}
});
}
privatevoidshowRateAppFallbackDialog(){
newMaterialAlertDialogBuilder(this)
.setTitle(R.string.rate_app_title)
.setMessage(R.string.rate_app_message)
.setPositiveButton(R.string.rate_btn_pos,(dialog,which)->{
})
.setNegativeButton(R.string.rate_btn_neg,
(dialog,which)->{
})
.setNeutralButton(R.string.rate_btn_nut,
(dialog,which)->{
})
.setOnDismissListener(dialog->{
})
.show();
}
}
HowtotesttheIn-AppReview?
Tocheckthein-appreviewflow,youmustalreadyhavetheappapprovedonPlaystore.Thisdoesnotmeanthattheapplicationshouldbeavailabletothepublic.Attheveryleast,youshouldhaveanaccountreadyforinternaltestingorinternalapplicationsharing.
YoucanuseInternalTestTracktoreleasetheappandtestthein-appreviewflow.
YoucanuseInternalAppSharingtotestthein-appreviewflow.
YoucanfindmoreinformationaboutthetestpartontheAndroidDeveloperpage.OurLaravelProducts