I have a button that I want it to send me to the Play Store to rate the app. couldn't find any about jetpack compose
CodePudding user response:
Set up your development environment
The Play In-App Review Library is a part of the Google Play Core libraries. Please include the following Gradle dependency to integrate the Play In-App Review Library.
// 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.0'
// For Kotlin users also add the Kotlin extensions library for Play In-App Review:
implementation 'com.google.android.play:review-ktx:2.0.0'
...
}
Create the ReviewManager and Request a ReviewInfo object
The ReviewManager
is the interface that lets your app start an in-app review flow. Obtain it by creating an instance using the ReviewManagerFactory
.
Follow the guidance about when to request in-app reviews to determine good points in your app's user flow to prompt the user for a review (for example, when the user completes a level in a game). When your app reaches one of these points, use the ReviewManager
instance to create a request task. If successful, the API returns the ReviewInfo
object needed to start the in-app review flow.
val manager = ReviewManagerFactory.create(requireActivity())
// val manager = FakeReviewManager(requireActivity())
val request = manager.requestReviewFlow()
request.addOnCompleteListener { task ->
if (task.isSuccessful) {
val reviewInfo = task.result
val flow = manager.launchReviewFlow(requireActivity(), reviewInfo)
flow.addOnCompleteListener {}
} else {
Toast.makeText(requireActivity(), "Error", Toast.LENGTH_SHORT).show()
}
}
CodePudding user response:
Call this method inside the onClick of your button.
fun openPlayStore(activityContext: Context, appURL: String) {
val playIntent: Intent = Intent().apply {
action = Intent.ACTION_VIEW
data = Uri.parse(appURL)
}
try {
activityContext.startActivity(playIntent)
} catch (e: Exception) {
// handle the exception
}
}
You should pass activity context (not application context).