Android In App Review

Jan 28 2021 · Kotlin 1.4, Android 5, Android Studio 4

Part 1: Implementing In App Review

09. Add Final Touches

Episode complete

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 08. Test Your In App Review Feature

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 09. Add Final Touches

If you want to access the current live version of the code for the raywenderlich.com app, known as Emitron, head over to its public repository: https://github.com/razeware/emitron-Android.

Additionally, you can contribute to the repository by looking at open issues and submitting a pull request, following the repository instructions.

If you want to check out the official documentation, head over to: https://developer.android.com/guide/playcore/in-app-review.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Now that you’ve built everything and tested your In App Review feature, it’s time to improve the experience and add some final touches. Open the InAppReviewManagerImpl.kt file and change the startReview() function like so:

  override fun startReview(activity: Activity) {
    if (reviewInfo != null) {
      reviewManager.launchReviewFlow(activity, reviewInfo).addOnCompleteListener { reviewFlow ->
        onReviewFlowLaunchCompleted(reviewFlow)
      }
    } else {
      sendUserToPlayStore()
    }
  }

  private fun onReviewFlowLaunchCompleted(reviewFlow: Task<Void>) {
    if (reviewFlow.isSuccessful) {
      logSuccess()
    } else {
      sendUserToPlayStore()
    }
  }
  private fun sendUserToPlayStore() {
    val appPackageName = context.packageName

    try {
      context.startActivity(
        Intent(
          Intent.ACTION_VIEW,
          Uri.parse("market://details?id=$appPackageName")
        )
      )
    } catch (error: Error) {
      context.startActivity(
        Intent(
          Intent.ACTION_VIEW,
          Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")
        )
      )
    }
  }
  fun clearIfUserDidNotRate()

  override fun clearIfUserDidNotRate() {
    if (!hasUserRatedApp()) {
      sharedPreferences.edit {
        putBoolean(KEY_CHOSEN_RATE_LATER, false)
        putLong(KEY_RATE_LATER_TIME, 0)
      }
    }
  }