{"id":1510,"date":"2022-10-14T13:31:58","date_gmt":"2022-10-14T13:31:58","guid":{"rendered":"https:\/\/infotheme.net\/blog\/?p=1510"},"modified":"2022-10-14T14:16:51","modified_gmt":"2022-10-14T14:16:51","slug":"android-rate-app-using-google-in-app-review-api","status":"publish","type":"post","link":"https:\/\/infotheme.net\/blog\/android-rate-app-using-google-in-app-review-api\/","title":{"rendered":"Android Rate App using Google In-App Review API"},"content":{"rendered":"\n<p>Once your app is live on playstore, app rating and reviews are very crusical factors to drive more downloads. To achive this, we usually ask users to rate the app by showing a dialog with couple of buttons and redirecting them to playstore. With this user experience, there are chances that user might not come back to our app once redirected to playstore. Also a novice user finds it difficult to rate the app on playstore.<\/p>\n\n\n\n<p>Luckly google provided an API called\u00a0<a href=\"https:\/\/developer.android.com\/guide\/playcore\/in-app-review\" data-type=\"URL\" data-id=\"https:\/\/developer.android.com\/guide\/playcore\/in-app-review\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">In-App Review<\/a>\u00a0to show the rating widget in the app itself without user leaving the app.<\/p>\n\n\n\n<p>The In-App Review is part of play core library. Once the widget is integrated, we can see the rating widget displayed in the same app in a bottom sheet.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-example.jpg\"><img loading=\"lazy\" width=\"1024\" height=\"742\" src=\"https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-example-1024x742.jpg\" alt=\"\" class=\"wp-image-1511\" srcset=\"https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-example-1024x742.jpg 1024w, https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-example-300x217.jpg 300w, https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-example-768x557.jpg 768w, https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-example.jpg 1500w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#Pointers_on_In-App_Review_API\"><span class=\"toc_number toc_depth_1\">1<\/span> Pointers on In-App Review API<\/a><\/li><li><a href=\"#Integrating_In-App_Review_API\"><span class=\"toc_number toc_depth_1\">2<\/span> Integrating In-App Review API<\/a><\/li><li><a href=\"#Testing_In-App_Review_Flow\"><span class=\"toc_number toc_depth_1\">3<\/span> Testing In-App Review Flow<\/a><\/li><\/ul><\/div>\n<h2><span id=\"Pointers_on_In-App_Review_API\">Pointers on In-App Review API<\/span><\/h2>\n\n\n\n<ul><li>In-app review works only on android devices running\u00a0<strong>Android 5.0<\/strong>\u00a0(API level 21) or higher that have the Google Play Store installed.<\/li><li>The in-app review API is subject to quotas. The API decides how often the review widget should be shown to user. We shouldn\u2019t call this API frequently as once user quota is reached, the widget won\u2019t be shown to user which can break the user experience. You can read more about\u00a0<a rel=\"noreferrer noopener nofollow\" href=\"https:\/\/developer.android.com\/guide\/playcore\/in-app-review#quotas\" data-type=\"URL\" data-id=\"https:\/\/developer.android.com\/guide\/playcore\/in-app-review#quotas\" target=\"_blank\">Quotas<\/a>\u00a0here.<\/li><li>The review flow will be controlled by API itself. We shouldn\u2019t try to alter the design or place approrpiate content on top of the widget. You can read more about Design Guidelines\u00a0<a rel=\"noreferrer noopener nofollow\" href=\"https:\/\/developer.android.com\/guide\/playcore\/in-app-review#design-guidelines\" data-type=\"URL\" data-id=\"https:\/\/developer.android.com\/guide\/playcore\/in-app-review#design-guidelines\" target=\"_blank\">here<\/a><\/li><li>The review flow doesn\u2019t indicate whether user has reviewed the app or not, even it won\u2019t tell us whether the widget has shown to user or not.<\/li><\/ul>\n\n\n\n<h2><span id=\"Integrating_In-App_Review_API\">Integrating In-App Review API<\/span><\/h2>\n\n\n\n<p>Integrating In-App review is very simple. It can be achived with very minimal code. Let\u2019s see how to integrate it.<\/p>\n\n\n\n<p><strong>1<\/strong>. The In-App review API is part of\u00a0<strong>Play Core API<\/strong>, so you have to include the library in your app\u2019s\u00a0<strong>build.gradle<\/strong>. Here I am adding material library as well as I want to show fallback\u00a0<a href=\"https:\/\/material.io\/develop\/android\/components\/dialogs\" data-type=\"URL\" data-id=\"https:\/\/material.io\/develop\/android\/components\/dialogs\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">rating dialog<\/a>\u00a0if there is any error in in-app review API.<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\napp\/build.gradle\n\/\/ Play core library\nimplementation &quot;com.google.android.play:core:1.8.0&quot;\n \n\/\/ optional material library to show the fallback rate us dialog\nimplementation &quot;com.google.android.material:material:1.3.0-alpha02&quot;\n<\/pre>\n\n\n<p><strong>2<\/strong>. The next step is creating the instance of\u00a0<a href=\"https:\/\/developer.android.com\/reference\/com\/google\/android\/play\/core\/review\/ReviewManager\" data-type=\"URL\" data-id=\"https:\/\/developer.android.com\/reference\/com\/google\/android\/play\/core\/review\/ReviewManager\" rel=\"nofollow noopener\" target=\"_blank\">ReviewManager<\/a>\u00a0interface. This class provides necessary methods to start the review flow.<\/p>\n\n\n\n<ul><li>Once the new instance is created, we need to call&nbsp;<em>requestReviewFlow()<\/em>&nbsp;task which returns the&nbsp;<strong>ReviewInfo<\/strong>&nbsp;object upon on successful completion.<\/li><li>Using the&nbsp;<strong>ReviewInfo<\/strong>&nbsp;object, we need to call&nbsp;<em>launchReviewFlow()<\/em>&nbsp;method to start the review flow.<\/li><li>For some reason, if the requestReviewFlow fails, we can launch the usual Rate App dialog that redirects user to playstore app.<\/li><li>Below,&nbsp;<em>showRateApp()<\/em>&nbsp;method starts the in-app review flow. The&nbsp;<em>showRateAppFallbackDialog()<\/em>&nbsp;method acts as fallback method if requestReviewFlow throws an error. This fallback method shows usual material dialog with three buttons to redirect user to playstore app.<\/li><\/ul>\n\n\n\n<p>Here is the complete code required for in-app review flow.<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nMainActivity.java\nimport android.os.Bundle;\nimport androidx.appcompat.app.AppCompatActivity;\nimport com.google.android.material.dialog.MaterialAlertDialogBuilder;\nimport com.google.android.play.core.review.ReviewInfo;\nimport com.google.android.play.core.review.ReviewManager;\nimport com.google.android.play.core.review.ReviewManagerFactory;\nimport com.google.android.play.core.tasks.Task;\n \npublic class MainActivity extends AppCompatActivity {\n \n    private ReviewManager reviewManager;\n \n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n \n        init();\n    }\n \n    private void init() {\n        reviewManager = ReviewManagerFactory.create(this);\n \n        findViewById(R.id.btn_rate_app).setOnClickListener(view -&gt; showRateApp());\n    }\n \n    \/**\n     * Shows rate app bottom sheet using In-App review API\n     * The bottom sheet might or might not shown depending on the Quotas and limitations\n     * https:\/\/developer.android.com\/guide\/playcore\/in-app-review#quotas\n     * We show fallback dialog if there is any error\n     *\/\n    public void showRateApp() {\n        Task&lt;ReviewInfo&gt; request = reviewManager.requestReviewFlow();\n        request.addOnCompleteListener(task -&gt; {\n            if (task.isSuccessful()) {\n                \/\/ We can get the ReviewInfo object\n                ReviewInfo reviewInfo = task.getResult();\n \n                Task&lt;Void&gt; flow = reviewManager.launchReviewFlow(this, reviewInfo);\n                flow.addOnCompleteListener(task1 -&gt; {\n                    \/\/ The flow has finished. The API does not indicate whether the user\n                    \/\/ reviewed or not, or even whether the review dialog was shown. Thus, no\n                    \/\/ matter the result, we continue our app flow.\n                });\n            } else {\n                \/\/ There was some problem, continue regardless of the result.\n                \/\/ show native rate app dialog on error\n                showRateAppFallbackDialog();\n            }\n        });\n    }\n \n    \/**\n     * Showing native dialog with three buttons to review the app\n     * Redirect user to playstore to review the app\n     *\/\n    private void showRateAppFallbackDialog() {\n        new MaterialAlertDialogBuilder(this)\n                .setTitle(R.string.rate_app_title)\n                .setMessage(R.string.rate_app_message)\n                .setPositiveButton(R.string.rate_btn_pos, (dialog, which) -&gt; {\n \n                })\n                .setNegativeButton(R.string.rate_btn_neg,\n                        (dialog, which) -&gt; {\n                        })\n                .setNeutralButton(R.string.rate_btn_nut,\n                        (dialog, which) -&gt; {\n                        })\n                .setOnDismissListener(dialog -&gt; {\n                })\n                .show();\n    }\n}\n<\/pre>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-dialog-example.jpg\"><img loading=\"lazy\" width=\"1024\" height=\"742\" src=\"https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-dialog-example-1024x742.jpg\" alt=\"\" class=\"wp-image-1512\" srcset=\"https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-dialog-example-1024x742.jpg 1024w, https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-dialog-example-300x217.jpg 300w, https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-dialog-example-768x557.jpg 768w, https:\/\/infotheme.net\/blog\/wp-content\/uploads\/2022\/10\/android-in-app-review-app-dialog-example.jpg 1500w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2><span id=\"Testing_In-App_Review_Flow\">Testing In-App Review Flow<\/span><\/h2>\n\n\n\n<p>To test the in-app review flow, you should have the app approved already on PlayStore. This doesn\u2019t mean the app should be available to public. At least you should have the account ready for\u00a0<a href=\"https:\/\/support.google.com\/googleplay\/android-developer\/answer\/3131213?hl=en\" data-type=\"URL\" data-id=\"https:\/\/support.google.com\/googleplay\/android-developer\/answer\/3131213?hl=en\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Internal Testing<\/a>\u00a0or\u00a0<a href=\"https:\/\/support.google.com\/googleplay\/android-developer\/answer\/9303479?hl=en\" data-type=\"URL\" data-id=\"https:\/\/support.google.com\/googleplay\/android-developer\/answer\/9303479?hl=en\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Internal App Sharing<\/a>.<\/p>\n\n\n\n<ul><li>You can use Internal Test Track to release the app and test the in-app review flow.<\/li><li>You can use Internal App Sharing to test the in-app review flow.<\/li><\/ul>\n\n\n\n<p>You can find more info on testing part on android developer\u00a0<a href=\"https:\/\/developer.android.com\/guide\/playcore\/in-app-review\/test\" data-type=\"URL\" data-id=\"https:\/\/developer.android.com\/guide\/playcore\/in-app-review\/test\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">page<\/a>. If you have any queries, please let me know in the comments section below.<\/p>\n\n\n\n<p>Cheers!<br>Happy Coding \ud83d\ude00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once your app is live on playstore, app rating and reviews are very crusical factors to drive more downloads. To achive this, we usually ask [&hellip;] <span class=\"read-more-link\"><a class=\"read-more\" href=\"https:\/\/infotheme.net\/blog\/android-rate-app-using-google-in-app-review-api\/\">Read More<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":1513,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[157,135,1],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/posts\/1510"}],"collection":[{"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/comments?post=1510"}],"version-history":[{"count":1,"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/posts\/1510\/revisions"}],"predecessor-version":[{"id":1514,"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/posts\/1510\/revisions\/1514"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/media\/1513"}],"wp:attachment":[{"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/media?parent=1510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/categories?post=1510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infotheme.net\/blog\/wp-json\/wp\/v2\/tags?post=1510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}