Google Play In-App Review using Android Studio - Section.io

文章推薦指數: 80 %
投票人數:10人

Google announced an in-app review API that prompts users to submit Play store ratings and reviews without leaving the application and ... Platform gps_fixedSectionEdgePlatform KubernetesEdgeInterface(KEI) AdaptiveEdgeEngine(AEE) GlobalEdgeNetwork view_moduleCorePlatformFeatures API Security Observability select_allAdd-OnEdgeServices PlatformExtensions RecommendedPartners Docs Resources Blog EdgeContentLibrary SolutionBriefs EngineeringEducation AboutSectionWE'REHIRING Pricing Platform gps_fixedSectionEdgePlatform KubernetesEdgeInterface(KEI) AdaptiveEdgeEngine(AEE) GlobalEdgeNetwork view_moduleCorePlatformFeatures API Security Observability select_allAdd-OnEdgeServices PlatformExtensions RecommendedPartners Docs Resources Blog ContentLibrary SolutionBriefs EngineeringEducation AboutSectionWE'REHIRING Pricing EngEdAuthorBio JosephChege JosephChegeisanundergraduatestudenttakingaBachelorinBusinessInformationTechnology,a4th-yearstudentatDedanKimathiUniversityofTechnology.JosephisfluentinAndroidMobileApplicationDevelopmentandhasalotofpassionforback-enddevelopment. Viewauthor'sfullprofile EngEdCommunity Section’sEngineeringEducation(EngEd)ProgramfostersacommunityofuniversitystudentsinComputerSciencerelatedfieldsofstudytoresearchandsharetopicsthatarerelevanttoengineersinthemoderntechnologylandscape.YoucanfindmoreinformationandprogramguidelinesintheGitHubrepository.Ifyou'recurrentlyenrolledinaComputerSciencerelatedfieldofstudyandareinterestedinparticipatingintheprogram,pleasecompletethisform . GooglePlayIn-AppReviewusingAndroidStudio December14,2020 Inthisguide,wewilllearnhowtoimplementtheratethisappfunctionalitywithinyourAndroidapplicationusingGooglecorein-appreviewAPI. Whenauserisinteractingwithyourapplication,youalwayswanttogetfeedback.Feedbackwillgiveyouinsightintowhatyourusersthinkaboutyourapplication. Intheolddays,auserwouldhavetoopentheGooglePlaystoretowriteareview.Insomefashion,youwoulduseafallbackreviewdialogwithsome“calltoaction”buttonstonudgetheusertoreviewyourapplication.Iftheuseragrees,thebuttonredirectstothePlaystoresothattheusercanwriteareviewaboutyourapplication. Thisapproachdoesnotpromoteausergoodexperienceandcanpotentiallyruinyourapplication’sreputationamongusers.Tomakemattersworse,thismethoddoesn’testablishcommunicationbetweenthePlaystoreandyourapplication;itwillkeeppoppingupevenafterauserleavesareview. Thistypeofcalltoactionwillforceyourusertoleaveyourapplication.Youdon’twantsuchascenario,asthere’sachancethatausermaynotreopenyourapplicationonceredirectedtotheplaystore. Googleannouncedanin-appreviewAPIthatpromptsuserstosubmitPlaystoreratingsandreviewswithoutleavingtheapplicationandwithoutopeningthePlaystoreeither.Users’reviews/ratingswilleventuallybedisplayedintheGooglePlaystore. Thisencouragesuserstogivefeedbackonyourapplication. Imagesource Thisishowthein-appreviewAPIlookscomparedtotheoldfallbackdialog. Typically,thisAPIconceptisabetterwayofaskingusersforareviewthanthefallbackratedialog. Prerequisites ThisguideassumesyouhavepriorknowledgeofAndroidapplicationdevelopmentusingAndroidStudio. Tocarryouttestingyouwillneed: AGooglePlayConsoleaccount. AnapplicationalreadypublishedintheGooglePlaystore. Whyyoushouldaskyourusersforreviews Reviewsplayamarketingroleinyourapplication.Theyareacrucialpartofsecuringmoredownloadsbecausetheycanconvinceanewuserwhethertheyshoulddownloadtheapplication.There’sagoodchanceanewuserwillcheckreviewsandratingstodecidewhichapplicationtotry.Thereviewssharetheexperiencesofprevioususers. Reviewsalsoformalineofcommunicationbetweenyouandyourusers,astheytellyouwhattoimproveinyourapplication.Potentially,ausercouldexperienceabugwhileinteractingwithyourapplication.Feedbackletsyouknowthatsomethingmightnotbeworkingwell,givingyouanudgetofixsaidbug. ImprovementonyourPlaystorerankingcanmakeyourapplicationmorediscoverableviaorganicsearches.Apartfromkeywordsthatyouaddsuchastheapplicationtitleanddescription,GooglePlaystoreindexesalmosteverytextinyourstorelisting. Reviewsarepartofthistextbecausetheyappearinyourstorelisting.Whenindexed,yourapplicationbecomesmorediscoverabletotherelevantusers.Thistranslatestoagoodranking,whichresultsinmoredownloadsfromtrafficconversion. Whentoshowin-appreviews Googlein-appreviewisagreatconcept.However,youshouldbesmartaboutwhentoimplementin-appreviews. Typically,youdon’twanttoaskausertorateyourapplication,forexample,inthemiddleofagame.Thiswillleadtoabaduserexperience,andthechancesarethatusersmightwritenegativereviews.Youshouldstrategicallyknowwhenisappropriatetoshowareviewdialog. Forexample,afterauserhasfinishedplayingaparticulargamelevel,thatwouldbeaperfectmomenttodoso.Thiswillensuretheusergivesareviewthataccuratelyreflectstheirexperienceplayingthatgame. Anothercasewouldbethatyouhave,say,ane-commerceapplication.Inthiscase,itwouldbeinappropriatetotellausertoreviewtheappinthemiddleofmakinganorder. Youwanttheusertohaveenoughinformationaboutyourapplicationservicesbeforesubmittingareview.Inthiscase,youwouldaskausertowriteareviewwhentheorderhasbeenprocessed,tocapturetherightmoment. Youdon’twanttoshowthereviewdialogwhenauserisyettointeractwithyourapplicationenoughtogiveadequatefeedback. WithGoogleCore,theAPIisdesignedtorespectuserprivacy.Theratingsheetdoesnotshowupatanytime.It’snotattachedtoanycalltoactionevent.TolimitAPImisuse,theAPIhasquotalimitsperuser. However,Googlehasnotprovidedtheexactnumberoftimestheratingdialogwillopenupperuser.AsimilariOSAPIhasitsquotalimitssetthreetimesayearperuser,whichmakessense,asthiswillnotbeannoyingtotheuser. Checkthedocumentationguidelinesregardingwhenyoushouldrequestthereviewflow. TheAPIstatesthatyouneedtonotethefollowing: Howyouaskforreviewsmatters.WhenusingthisAPI,youshouldnotaskpredictiveoropinionatedquestionsbeforeorafterthereviewsheetdialogsshowtheappinyourapplication.Thesequestionsinclude: Wouldyouratethisapplicationfivestars? Doyoulikethisapp? TheAPIalsoadvisesyouonlytoshowdialogonceauserhasenoughexperiencewithyourapplication.It’snotagoodpracticetoaskausertowriteareviewbeforetheappdeliversvaluetothatuser.Chancesare,theuserwillgetannoyedandskipthereview.Andiftheydon’tskipit,theywillgivenegativereviews. InordertominimizeAPIusageandavoidannoyingusers,itwouldbebestifyoudidnotexcessivelyaskuserstowritereviews. Implementation GoogledescribesthisAPIaslight.It’ssimpletointegratewithinyourapplication.Tobegin,identifyanactivitywhereyouwanttoimplementthereviewflow.Onceimplemented,theAPIwillhandlethereviewflowforyou. Requirements AnAndroidphonerunningAndroid5.0(API21)orhigher.ThedeviceshouldhaveGooglePlayinstalledandconnectedwithaGmailaccount. GooglePlayCoreLibrary,version1.8.0orhigher. Integration Step1:Addingdependency AddGoogleCoreLibrarytoyourbuild.gradlefile. implementation'com.google.android.play:core:1.9.0' Synctodownloadthelibrarytohaveaccesstothenecessaryclassestoinitiatereviewflow. Alwaysensurethatyouareusingthelatestlibraryversion.Checkherefornewlyaddedversions. Step2:Creatinganinstanceofa‘ReviewManager’ TheReviewManagerprovidestherequiredfunctionsthattriggerthereviewflow. Theyinclude: requestReviewFlow()—fetchesapplicationinformationfromthePlaystore. launchReviewFlow()—initiatesthereviewflow. DeclareReviewManagerrightaboveonCreate(). TocreateaninstanceofReviewManager: DeclareReviewManagerrightaboveonCreate(). UseReviewManagerFactorycallingthecreatefunction,andpassyourapplicationcontexttoit. reviewManager=ReviewManagerFactory.create(getApplicationContext()); Step3:Requestingreviewinfo requestReviewFlow()communicateswiththeGooglePlaystoreremotelytogettheinformationthatreferencesyourapplication. DeclareReviewInfo. ReviewInforeviewInfo; ReviewInfoholdsthisinformation,thatwillbeusedtotriggerthereviewflowprocesstotheenduser. Taskmanager=reviewManager.requestReviewFlow(); manager.addOnCompleteListener(task->{ if(task.isSuccessful()){ reviewInfo=task.getResult(); }else{ } }); CallingrequestReviewFlow()willreturnthedataassociatedwithyourplaystoreapplication.Thisfunctionperformsanasynchronousoperation,meaningwehavetowaitfortheoperationtocomplete. Forthisreason,weneedtoassignalistener.ThelistenerwillletReviewManagerknowwhentheTaskiscompletedandassigntherequest’sresultstoReviewInfo. Step4:LaunchingReviewFlow ReferencingtheReviewFlow,wecanstartandshowthereviewdialogtotheuser.However,insomeinstances,requestReviewFlow()canfailtogettheapplicationinformation,meaningthatReviewFlowwillbenull. Theseinstancesinclude: Poorinternetconnection. Auserhaspreviouslywrittenareviewforyourapplication. Quotarestriction.DuetothequotaimposedbythisAPI,noteveryrequestwillbesuccessful. Forthisreason,weneedtostartlaunchReviewFlow()ifReviewFlowisnotnull.MakesureyouassignReviewFlowtonull. ReviewInforeviewInfo=null; Whennull,theReviewManagerwillterminatethereviewflow. if(reviewInfo!=null){ Taskflow=reviewManager.launchReviewFlow(this,reviewInfo); flow.addOnCompleteListener(newOnCompleteListener(){ @Override publicvoidonComplete(Tasktask){ Toast.makeText(getApplicationContext(),"InAppRatingcomplete",Toast.LENGTH_LONG).show(); } }); } else{ } WhenrequestReviewFlow()issuccessful,ReviewFlowwillbeassignedtotherequestresults.YouneedtocheckifreviewInfo!=nulltotriggerthereviewflowwithlaunchReviewFlow().ThentheAPIwillhandlethereview’scommentandratingandupdateyourapplicationstorelistingshowingthem. ThisAPIstate’sthatifanerroroccursduringthereviewflow,youshouldneverinformtheuserorchangeyournormalapplicationflow.TheappshouldcontinueitsusualflowafteronCompleteiscalled. FinalActivityCode Remembertopressalt+enteronaPCandoption+enteronaMactoimporttheclassesaftercopyingandpastingthecodeblocksintoyourIDE. publicclassMainActivityextendsAppCompatActivity{ ReviewManagerreviewManager; ReviewInforeviewInfo=null; @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getReviewInfo(); startReviewFlow(); } privatevoidgetReviewInfo(){ reviewManager=ReviewManagerFactory.create(getApplicationContext()); Taskmanager=reviewManager.requestReviewFlow(); manager.addOnCompleteListener(task->{ if(task.isSuccessful()){ reviewInfo=task.getResult(); }else{ Toast.makeText(getApplicationContext(),"InAppReviewFlowfailedtostart",Toast.LENGTH_LONG).show(); } }); } publicvoidstartReviewFlow(){ if(reviewInfo!=null){ Taskflow=reviewManager.launchReviewFlow(this,reviewInfo); flow.addOnCompleteListener(newOnCompleteListener(){ @Override publicvoidonComplete(Tasktask){ Toast.makeText(getApplicationContext(),"InAppRatingcomplete",Toast.LENGTH_LONG).show(); } }); } else{ Toast.makeText(getApplicationContext(),"InAppRatingfailed",Toast.LENGTH_LONG).show(); } } } Testing Totestourapplication,wewilluseinternalappsharing.Toconfirmthatthisworks,addaButtontotriggerthereviewflow.Remember,weareusingacalltoactionfortesting.Inproductionapplications,callstoactionsuchasButtonshouldbeavoidedwhenusingthisAPI. Addabuttoninyouractivity.xml Declarethebutton ButtonmButton; BelowonCreate, CreateaninstanceofthemButton mButton=findViewById(R.id.button); AddOnClickListenerandcallstartReviewFlow() mButton.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){ startReviewFlow(); } }); Howtotest Generateasignedappbundle/APK.NotetheAPKsigningkeyandtheapplicationIdshouldbethesameasthealreadypublishedapplication. SharethegeneratedAPKwithatester.Todothat,selectthepublishedapplicationintheGoogleconsole,navigatetoInternalAppSharing,anduploadthegeneratedAPKthere.CheckhowtouseGoogleInternalAppSharing. Copytheupload’sshareablelinkandshareitwithatester.Inthiscase,atestershouldbeusinganAndroidmobilephone. Openthesharedlinkonthephone’sbrowser.YouwillbepromptedtoopenwiththeGooglePlaystore.Doso.ThiswilllaunchaPlaystorescreen. Downloadtheappandwaitfortheinstallationtocomplete. LaunchtheapplicationandclickSHOWINAPPREVIEWDIALOGtostartthereviewflow,asshownintheimagebelow. Note: Sinceweacarryingoutatest,thesubmitbuttonwillbeinactive. Ifyouhavepreviouslyreviewedtheapplication,deleteyourcommentintheGooglePlaystore.Otherwise,thereviewsheetwon’tpopup. Formorereference,checkthecodeonGitHub. Ihopethisguideisahelpfulsourceonhowtoaskusersforreviewsaswellasimplementin-appreviewswithinyourapplication. PeerReviewContributionsby:LinusMuema



請為這篇文章評分?