Created
April 2, 2021 09:54
-
-
Save huuphuoc1396/244f98c9fb9088c29264da5a786bbba5 to your computer and use it in GitHub Desktop.
Google Play In-App Review API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.androidinappreviews | |
import android.os.Bundle | |
import android.util.Log | |
import androidx.appcompat.app.AppCompatActivity | |
import com.example.androidinappreviews.databinding.ActivityMainBinding | |
import com.google.android.play.core.review.ReviewManagerFactory | |
class MainActivity : AppCompatActivity() { | |
private lateinit var viewDataBinding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
viewDataBinding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(viewDataBinding.root) | |
viewDataBinding.reviewButton.setOnClickListener { | |
requestInAppReview() | |
} | |
} | |
private fun requestInAppReview() { | |
val reviewManager = ReviewManagerFactory.create(this) | |
val reviewRequest = reviewManager.requestReviewFlow() | |
reviewRequest.addOnCompleteListener { task -> | |
if (task.isSuccessful) { | |
val reviewInfo = task.result | |
val reviewFlow = reviewManager.launchReviewFlow(this, reviewInfo) | |
reviewFlow.addOnCompleteListener { result -> | |
Log.i(TAG, "Reviewed successfully: ${result.isSuccessful}") | |
} | |
} else { | |
val exception = task.exception | |
Log.i(TAG, "Reviewed error: ${exception?.message ?: ""}") | |
} | |
} | |
} | |
companion object { | |
private const val TAG = "MainActivity_TAG" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment