این راهنما نحوه ادغام مرورهای درونبرنامه را در برنامه شما بااستفاده از Kotlin یا Java شرح میدهد. اگر از کد بومی، Unity، یا Unreal Engine استفاده میکنید، راهنماهای ادغام جداگانهای وجود دارد.
راهاندازی محیط توسعه نرمافزار
«کتابخانه مرور درونبرنامه Play» بخشی از کتابخانههای هسته Google Play است. برای ادغام «کتابخانه مرور درونبرنامه Play»، وابستگی 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' ... }
کاتلین
// 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. });
مراحل بعدی
جریان مرور درونبرنامهای برنامهتان را آزمایش کنید تا مطمئن شوید ادغام شما بهدرستی کار میکند.