Integrate in-app reviews (Native)

This guide describes how to integrate in-app reviews in your app using native (C or C++) code. There are separate integration guides if you are using Kotlin or Java or Unity.

Native SDK overview

The Play Core Native SDK is part of Play Core SDK family. The Play Core Native SDK includes a C header file, review.h, that wraps ReviewManager from the Java Play Core SDK. This header file allows your app to call the API directly from your native code. For an overview of the public functions that are available, see the Play Review native module documentation.

ReviewManager_requestReviewFlow starts a request that gathers the information that is required to launch the in-app review flow later. You can track the result of the request using ReviewManager_getReviewStatus. For more information about all the statuses that ReviewManager_getReviewStatus can return, see ReviewErrorCode.

Both the request and launch functions return REVIEW_NO_ERROR if the function succeeds.

Set up your development environment

To set up your development environment, follow the setup instructions in the Native section of the Play Core library guide.

Include review.h

After integrating the Play Core Native SDK into your project, include the following line in files that will contain API calls:

#include "play/review.h"

Initialize the Review API

Whenever you want to use the API, you must initialize it first by calling the ReviewManager_init function, as shown in the following example built with android_native_app_glue.h:

void android_main(android_app* app) {
  app->onInputEvent = HandleInputEvent;

  ReviewErrorCode error_code = ReviewManager_init(app->activity->vm, app->activity->clazz);
  if (error_code == REVIEW_NO_ERROR) {
    // You can use the API.

Request the in-app review flow

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, after a user dismisses the summary screen at the end of a level in a game). When your app gets close one of these points, call ReviewManager_requestReviewFlow to asynchronously request the information that your app needs to launch an in-app review flow. Monitor the progress of the ReviewManager_requestReviewFlow operation by calling ReviewManager_getReviewStatus, for example once every frame. This might take up to a couple of seconds, so you should start this process before your app reaches the point when you want to show the in-app review flow.

ReviewErrorCode error_code = ReviewManager_requestReviewFlow();
if (error_code == REVIEW_NO_ERROR) {
    // The request has successfully started, check the status using
    // ReviewManager_getReviewStatus.
} else {
    // Error such as REVIEW_PLAY_STORE_NOT_FOUND indicating that the in-app
    // review isn't currently possible.

Handle statuses and launch the in-app review flow

Whenever a request has started or the in-app review flow is launched, you can check the status using ReviewManager_getReviewStatus. This allows you to define the logic depending on the API status. One way to approach this is to keep the status as a global variable and check whether the status is REVIEW_REQUEST_FLOW_COMPLETED when the user performs a certain action (for example, tapping a “Next Level” button in a game), as shown in the following example:

ReviewStatus status;
ReviewErrorCode error_code = ReviewManager_getReviewStatus(&status);
if (error_code != REVIEW_NO_ERROR) {
    // There was an error with the most recent operation.

switch (status) {
        // Request is ongoing. The flow can't be launched yet.
        // Request completed. The flow can be launched now.
        // The review flow is ongoing, meaning the dialog might be displayed.
        // The review flow has finished. Continue with your app flow (for
        // example, move to the next screen).
        // Unknown status.

When the status is REVIEW_REQUEST_FLOW_COMPLETED and your app is ready, launch the in-app review flow:

// This call uses android_native_app_glue.h.
ReviewErrorCode error_code = ReviewManager_launchReviewFlow(app->activity->clazz);
if (error_code != REVIEW_NO_ERROR) {
    // There was an error while launching the flow.

After launching the in-app review flow, keep checking the status for completion and continue with your app flow. A common way to handle this, would be by following the Game Loop pattern.

Free resources

Don't forget to free resources by calling the ReviewManager_destroy function once your app has finished using the API (for example, after the in-app review flow is completed).

void ReviewManager_destroy();

Next steps

Test your app's in-app review flow to verify that your integration is working correctly.