Skip to content

Instantly share code, notes, and snippets.

@ahmed-shehataa
Last active August 9, 2020 17:34
Show Gist options
  • Select an option

  • Save ahmed-shehataa/a4c72234a0fb164a5183d551111ace61 to your computer and use it in GitHub Desktop.

Select an option

Save ahmed-shehataa/a4c72234a0fb164a5183d551111ace61 to your computer and use it in GitHub Desktop.

Revisions

  1. ahmed-shehataa renamed this gist Aug 9, 2020. 1 changed file with 0 additions and 0 deletions.
  2. ahmed-shehataa created this gist Aug 9, 2020.
    38 changes: 38 additions & 0 deletions Launch In-app review api.kotlin
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    fun Activity.reviewAppDialog() {
    val manager = ReviewManagerFactory.create(this)

    (manager.requestReviewFlow()).addOnCompleteListener { request ->
    if (request.isSuccessful) {
    // We got the ReviewInfo object
    val reviewInfo = request.result
    manager.launchReviewFlow(this, reviewInfo)

    } else {
    // here ypu can call a normal review (send intent to google play or a browser)
    rateApp()
    }
    }

    }


    fun Activity.rateApp() {
    try {
    val sendIntent = Intent().apply {
    action = Intent.ACTION_SEND
    putExtra(
    Intent.ACTION_VIEW,
    Uri.parse("market://details?id=$packageName")
    )
    }
    startActivity(sendIntent)
    } catch (e: ActivityNotFoundException) {
    startActivity(
    Intent(
    Intent.ACTION_VIEW,
    Uri.parse("https://play.google.com/store/apps/details?id=$packageName")
    )
    )
    }

    }