readerlook-android
Image from https://android-developers.googleblog.com/
Technology

In-App Review Android

2 Mins read

We are waiting & hoping this for a long time and finally, the Android team released it on August 05 2020.

Google-Android released In-App review API and now android users able to give the review to our application without re-direct to Google Play application. User’s review is the most important thing for the application developer or a company because it helps us in application enhancement and improvement.

User reviews are valuable part for application development and due to previous functionality to give the review to an application we all are losing lots of reviews because every application user doesn’t want the interruption while they are playing a game or chatting or doing anything in the application, they just want the smooth user experience this interruption leads us to miss out many reviews.



In-App Review API

The in-app review API supports both public and private reviews for when your app is in beta. This API allows to ask for a review and the user can give the review without leaving the app and it is designed to be seamless for users.

The integration consists of four main steps:

1. Define the conditions and best place to ask for a review

2. Request the review flow to the API

3. Launch the review at an appropriate moment

4. Continue the flow after the review is completed

You should not force the user to give the review, whether the user gives the review or not application must run without any interruption. For the best user experience ask for the review when the user become familiar with your application.



How to use this API

This API is available for the Android devices (phones and tablets) running Android 5.0 (API level 21) or higher

// 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:core-ktx:1.8.0'
    ...
}


Add above dependency in build.gradle

class InAppReviewViewModel(private val reviewManager: ReviewManager) : ViewModel() {
    private var reviewInfo: Deferred<ReviewInfo>? = null

    @MainThread
    fun initReview() {
        if (reviewInfo == null) {
            reviewInfo = viewModelScope.async { reviewManager.requestReview() }
        }
    }

    suspend fun getReviewInfo(): ReviewInfo? = withContext(Dispatchers.Main.immediate) {
        initReview()
        return@withContext reviewInfo?.await().also {
            reviewInfo = null
        }
    }
}

class ReviewViewModelProviderFactory(
    private val manager: ReviewManager
) : ViewModelProvider.Factory {
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        return modelClass.getConstructor(ReviewManager::class.java).newInstance(manager)
    }
}


Create InAppReviewViewModel.kt and put that above code in that

package com.example.inappreviewdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.google.android.play.core.ktx.launchReview
import com.google.android.play.core.review.ReviewManager
import com.google.android.play.core.review.ReviewManagerFactory

class MainActivity : AppCompatActivity() {

    private lateinit var reviewManager: ReviewManager

    private val reviewViewModel by viewModels<InAppReviewViewModel> {
        ReviewViewModelProviderFactory(reviewManager)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        reviewManager = ReviewManagerFactory.create(this)


    }

    override fun onResume() {
        super.onResume()
        lifecycleScope.launchWhenResumed {
            reviewViewModel.getReviewInfo()?.let { reviewInfo ->
                reviewManager.launchReview(this@MainActivity, reviewInfo)
            }
        }
    }
}


Launch reviewManager onResume() or where you want to get the users review and then review flow work smoothly and the user’s review will be posted in the review section on the play store.

References:-
https://github.com/android/app-bundle-samples/tree/master/PlayCoreKtx
https://developer.android.com/guide/playcore/in-app-review/kotlin-java#kotlin
https://android-developers.googleblog.com/2020/08/in-app-review-api.html?linkId=96101923


Happy Coding!!

There are lots of things are going to come in Android-Development so for the future post notification subscribes to the newsletter. Hope you got something new by this article so please do comment and share this article to others and give them brief about this new API.

Related posts
Technology

Top Android Interview Questions on AsyncTask

6 Mins read
You have seen many articles related to android interview Q&A but they all not give you proper android interview Q&A, so in…
5 1 vote
Article Rating
2 Comments
Inline Feedbacks
View all comments
Yachika Joshi
Yachika Joshi
3 months ago

Hi Nitin,
Your article seems to be really helpful, I’ll try to implement this in my own code 🙂