简体   繁体   English

“评价此应用”-手机上 Google Play 商店应用中的链接

[英]“Rate This App”-link in Google Play store app on the phone

I'd like to put a "Rate This App"-link in an Android App to open up the app-listing in the user's Google Play store app on their phone.我想在 Android 应用程序中放置一个“评价此应用程序”链接,以在用户的​​手机上的 Google Play 商店应用程序中打开应用程序列表。

  1. What code do I have to write to create the market:// or http:// -link open in the Google Play store app on the phone?我必须编写什么代码才能在手机上的 Google Play 商店应用程序中创建market://http:// -link 打开?
  2. Where do you put the code?你把代码放在哪里?
  3. Does anyone have a sample implementation of this?有没有人有这个的示例实现?
  4. Do you have to specify the screen where the market:// or http:// link will be placed, and which is the best to use - market:// or http:// ?您是否必须指定将放置market://http://链接的屏幕,以及最好使用哪个屏幕 - market://http://

I open the Play Store from my App with the following code:我使用以下代码从我的应用程序打开 Play 商店:

            val uri: Uri = Uri.parse("market://details?id=$packageName")
            val goToMarket = Intent(Intent.ACTION_VIEW, uri)
            // To count with Play market backstack, After pressing back button, 
            // to taken back to our application, we need to add following flags to intent. 
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or
                    Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
            try {
                startActivity(goToMarket)
            } catch (e: ActivityNotFoundException) {
                startActivity(Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=$packageName")))
            }

Here is a working and up to date code :)这是一个有效且最新的代码:)

/*
* Start with rating the app
* Determine if the Play Store is installed on the device
*
* */
public void rateApp()
{
    try
    {
        Intent rateIntent = rateIntentForUrl("market://details");
        startActivity(rateIntent);
    }
    catch (ActivityNotFoundException e)
    {
        Intent rateIntent = rateIntentForUrl("https://play.google.com/store/apps/details");
        startActivity(rateIntent);
    }
}

private Intent rateIntentForUrl(String url)
{
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
    int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
    if (Build.VERSION.SDK_INT >= 21)
    {
        flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
    }
    else
    {
        //noinspection deprecation
        flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
    }
    intent.addFlags(flags);
    return intent;
}

Put the code in the Activity you would like to call it from.将代码放在您要从中调用它的Activity
When the user clicks a button to rate the app, just call the rateApp() function.当用户单击按钮对应用程序进行评分时,只需调用rateApp()函数即可。

我总是使用这个代码:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=PackageName")));

This is if you publish your app in both Google Play Store and Amazon Appstore.如果您在 Google Play 商店和 Amazon Appstore 中发布您的应用程序。 I also handle the case that users (especially in China) don't have both app store and browser.我还处理用户(特别是在中国)没有应用商店和浏览器的情况。

public void goToMyApp(boolean googlePlay) {//true if Google Play, false if Amazone Store
    try {
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "market://details?id=" : "amzn://apps/android?p=") +getPackageName())));
    } catch (ActivityNotFoundException e1) {
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "http://play.google.com/store/apps/details?id=" : "http://www.amazon.com/gp/mas/dl/android?p=") +getPackageName())));
        } catch (ActivityNotFoundException e2) {
            Toast.makeText(this, "You don't have any app that can open this link", Toast.LENGTH_SHORT).show();
        }
    }
}

Kotlin solution (In-app review API by Google in 2020): Kotlin 解决方案(Google 在 2020 年提供的应用内评论 API):

You can now use In app review API provided by Google out of the box.您现在可以开箱即用地使用 Google 提供的 In app review API。

First, in your build.gradle(app) file, add following dependencies (full setup can be found here )首先,在您的build.gradle(app)文件中,添加以下依赖项(完整设置可以在这里找到)

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:core:1.8.0'
    implementation 'com.google.android.play:core-ktx:1.8.1'
}

Create a method and put this code inside:创建一个方法并将此代码放入其中:

val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { request ->
    if (request.isSuccessful) {
        // We got the ReviewInfo object
        val reviewInfo = request.result
        val flow = manager.launchReviewFlow(activity, reviewInfo)
        flow.addOnCompleteListener { _ ->
          // The flow has finished. The API does not indicate whether the user
          // reviewed or not, or even whether the review dialog was shown. Thus, no
         // matter the result, we continue our app flow.
        }
    } else {
        // There was some problem, continue regardless of the result.
    }
}

Source 来源

在此处输入图片说明

You can always call getInstalledPackages() from the PackageManager class and check to make sure the market class is installed.您始终可以从PackageManager类调用getInstalledPackages()并检查以确保市场类已安装。 You could also use queryIntentActivities() to make sure that the Intent you construct will be able to be handled by something, even if it's not the market application.您还可以使用queryIntentActivities()来确保您构建的 Intent 能够被某些东西处理,即使它不是市场应用程序。 This is probably the best thing to do actually because its the most flexible and robust.这实际上可能是最好的做法,因为它最灵活和强大。

You can check if the market app is there by您可以通过以下方式检查市场应用程序是否在那里

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=foo"));
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);

If the list has at least one entry, the Market's there.如果列表至少有一个条目,则市场就在那里。

You can use the following to launch Android Market on your application's page, it's a bit more automated:您可以使用以下命令在您的应用程序页面上启动 Android Market,它的自动化程度更高:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=" + getPackageName()));
startActivity(i);

If you want to test this on your emulator you probably you don't have the market installed on it : see these links for more details:如果你想在你的模拟器上测试这个,你可能没有安装市场:有关更多详细信息,请参阅这些链接:

How To Enable the Android Market in the Google Android Emulator 如何在 Google Android Emulator 中启用 Android Market

Installing Google Play on Android Emulator 在 Android 模拟器上安装 Google Play

I use this approach to make user rate my apps:我使用这种方法让用户评价我的应用程序:

public static void showRateDialog(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setTitle("Rate application")
            .setMessage("Please, rate the app at PlayMarket")
            .setPositiveButton("RATE", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (context != null) {
                        String link = "market://details?id=";
                        try {
                            // play market available
                            context.getPackageManager()
                                    .getPackageInfo("com.android.vending", 0);
                        // not available
                        } catch (PackageManager.NameNotFoundException e) {
                            e.printStackTrace();
                            // should use browser
                            link = "https://play.google.com/store/apps/details?id=";
                        }
                        // starts external action
                        context.startActivity(new Intent(Intent.ACTION_VIEW, 
                                Uri.parse(link + context.getPackageName())));
                    }
                }
            })
            .setNegativeButton("CANCEL", null);
    builder.show();
}

Play Store Rating Play 商店评分

 btn_rate_us.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse("market://details?id=" + getPackageName());
                Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                // To count with Play market backstack, After pressing back button,
                // to taken back to our application, we need to add following flags to intent.
                goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                        Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                        Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                try {
                    startActivity(goToMarket);
                } catch (ActivityNotFoundException e) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
                }
            }
        });

A kotlin version一个 kotlin 版本

fun openAppInPlayStore() {
    val uri = Uri.parse("market://details?id=" + context.packageName)
    val goToMarketIntent = Intent(Intent.ACTION_VIEW, uri)

    var flags = Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
    flags = if (Build.VERSION.SDK_INT >= 21) {
        flags or Intent.FLAG_ACTIVITY_NEW_DOCUMENT
    } else {
        flags or Intent.FLAG_ACTIVITY_CLEAR_TASK
    }
    goToMarketIntent.addFlags(flags)

    try {
        startActivity(context, goToMarketIntent, null)
    } catch (e: ActivityNotFoundException) {
        val intent = Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName))

        startActivity(context, intent, null)
    }
}

You can use this, it works for me你可以用这个,它对我有用

public static void showRateDialogForRate(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setTitle("Rate application")
            .setMessage("Please, rate the app at PlayMarket")
            .setPositiveButton("RATE", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (context != null) {
                        ////////////////////////////////
                        Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
                        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                        // To count with Play market backstack, After pressing back button,
                        // to taken back to our application, we need to add following flags to intent.
                        goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                                Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |
                                Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                        try {
                            context.startActivity(goToMarket);
                        } catch (ActivityNotFoundException e) {
                            context.startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
                        }


                    }
                }
            })
            .setNegativeButton("CANCEL", null);
    builder.show();
}

关于所有基于 getPackageName() 策略实现的答案的一点是,如果您使用相同的代码库构建具有不同应用程序 ID 的多个应用程序(例如,一个白标产品)。

Another approach that may work for you is Linkify.另一种可能适合您的方法是 Linkify。 If I have a TextView that is asking the user to rate the app, I can linkify a couple of words in the text so they are highlighted and when the user touches them, the play store opens up, ready for their review:如果我有一个 TextView 要求用户对应用程序进行评分,我可以链接文本中的几个词,以便突出显示它们,当用户触摸它们时,Play 商店就会打开,准备好供他们查看:

class playTransformFilter implements TransformFilter {
   public String transformUrl(Matcher match, String url) {
        return "market://details?id=com.qwertyasd.yourapp";
   }
}

class playMatchFilter implements MatchFilter {
    public boolean acceptMatch(CharSequence s, int start, int end) {
        return true;
    }
}
text1 = (TextView) findViewById(R.id.text1);
text1.setText("Please rate it.");
final Pattern playMatcher = Pattern.compile("rate it");
Linkify.addLinks(text1, playMatcher, "", 
                   new playMatchFilter(), new playTransformFilter());

From now you can use In App Rating feature by Google .从现在开始,您可以使用Google 的应用内评分功能

Here is Kotlin/Java integration official guide 这是 Kotlin/Java 集成官方指南

The Google Play In-App Review API lets you prompt users to submit Play Store ratings and reviews without the inconvenience of leaving your app or game. Google Play In-App Review API 可让您提示用户提交 Play 商店评分和评论,而无需离开您的应用或游戏。

Generally, the in-app review flow (see figure 1) can be triggered at any time throughout the user journey of your app.通常,应用内审核流程(见图 1)可以在应用的整个用户旅程中随时触发。 During the flow, the user has the ability to rate your app using the 1 to 5 star system and to add an optional comment.在流程中,用户可以使用 1 到 5 星系统对您的应用进行评分并添加可选评论。 Once submitted, the review is sent to the Play Store and eventually displayed.提交后,评论将发送到 Play 商店并最终显示出来。

sc

You can use this simple code for rate your app in your activity.您可以使用这个简单的代码在您的活动中为您的应用评分。

try {
    Uri uri = Uri.parse("market://details?id=" + getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
    startActivity(new Intent(Intent.ACTION_VIEW,
    Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
}
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.StringRes;
import android.widget.Toast;

public class PlayStoreLink {

public void checkForUpdate(Context context, int applicationId) 
{
    try {
        context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse(context.getString(R.string.url_market_details)
                        + applicationId)));
    } catch (android.content.ActivityNotFoundException anfe) {
        try {
            context.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse(context.getString(R.string.url_playstore_app)
                            + applicationId)));
        } catch (Exception e) {
            Toast.makeText(context,
                    R.string.install_google_play_store,
                    Toast.LENGTH_SHORT).show();
        }
    }
}

public void moreApps(Context context, @StringRes int devName) {
    try {
        context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse(context.getString(R.string.url_market_search_app)
                        + context.getString(devName))));
    } catch (android.content.ActivityNotFoundException anfe) {
        try {
            context.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse(context.getString(R.string.url_playstore_search_app)
                            + context.getString(devName))));
        } catch (Exception e) {
            Toast.makeText(context,
                    R.string.install_google_play_store,
                    Toast.LENGTH_SHORT).show();
        }
    }
}

public void rateApp(Context context, int applicationId) {
    try {
        Uri uri = Uri.parse(context.getString(R.string.url_market_details)
                + applicationId);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH)
            flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        else
            flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
        intent.addFlags(flags);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        checkForUpdate(context, applicationId);
    }
}
}

<string name="install_google_play_store" translatable="false">Please install google play store and then try again.</string>
<string name="url_market_details" translatable="false">market://details?id=</string>
<string name="url_playstore_app" translatable="false">https://play.google.com/store/apps/details?id=</string>
<string name="url_market_search_app" translatable="false">market://search?q=pub:</string>
<string name="url_playstore_search_app" translatable="false">http://play.google.com/store/search?q=pub:</string>
<string name="app_link" translatable="false">https://play.google.com/store/apps/details?id=</string>

devName is the name of Developer Account on Play Store devName 是 Play 商店中开发者帐户的名称

I use the following approach by combining this and this answer without using exception based programming and also supports pre-API 21 intent flag.我使用以下方法将这个这个答案结合起来,而不使用基于异常的编程,并且还支持 API 21 之前的意图标志。

@SuppressWarnings("deprecation")
private Intent getRateIntent()
{
  String url        = isMarketAppInstalled() ? "market://details" : "https://play.google.com/store/apps/details";
  Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
  int intentFlags   = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
  intentFlags      |= Build.VERSION.SDK_INT >= 21 ? Intent.FLAG_ACTIVITY_NEW_DOCUMENT : Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
  rateIntent.addFlags(intentFlags);
  return rateIntent;
}

private boolean isMarketAppInstalled()
{
  Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=anyText"));
  return getPackageManager().queryIntentActivities(marketIntent, 0).size() > 0;
}


// use
startActivity(getRateIntent());

Since the intent flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET is deprecated from API 21 I use the @SuppressWarnings("deprecation") tag on the getRateIntent method because my app target SDK is below API 21.由于意图标志FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET从API 21弃用我使用@SuppressWarnings("deprecation")标签上getRateIntent方法,因为我的应用程序的目标SDK低于API 21。


I also tried the official Google way suggested on their website (Dec. 6th 2019).我还尝试了他们网站上建议的官方Google 方式(2019 年 12 月 6 日)。 To what I see it doesn't handle the case if the Play Store app isn't installed:如果没有安装 Play Store 应用程序,我认为它不会处理这种情况:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
    "https://play.google.com/store/apps/details?id=com.example.android"));
intent.setPackage("com.android.vending");
startActivity(intent);

Declare a method in you activity class.在您的活动类中声明一个方法。 Then copy and paste the code below.然后复制并粘贴下面的代码。

private void OpenAppInPlayStore(){

    Uri uri = Uri.parse("market://details?id=" + this.getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    // To count with Play market backstack, After pressing back button,
    // to taken back to our application, we need to add following flags to intent.
    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
            Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
            Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + this.getPackageName())));
    }

}

Now call this method from anywhere of your code.现在从代码的任何位置调用此方法。

Follow the image below from my practical project.按照我的实际项目中的下图进行操作。

在此处输入图片说明

Java solution (In-app review API by Google in 2020): Java 解决方案(Google 在 2020 年提供的应用内评论 API):

You can now use In app review API provided by Google out of the box.您现在可以开箱即用地使用 Google 提供的 In app review API。

First, in your build.gradle(app) file, add following dependencies (full setup can be found here )首先,在您的build.gradle(app)文件中,添加以下依赖项(完整设置可以在这里找到)

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:core:1.8.0'
}

Add this method to your Activity :将此方法添加到您的Activity

void askRatings() {
    ReviewManager manager = ReviewManagerFactory.create(this);
    Task<ReviewInfo> request = manager.requestReviewFlow();
    request.addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            // We can get the ReviewInfo object
            ReviewInfo reviewInfo = task.getResult();
            Task<Void> flow = manager.launchReviewFlow(this, reviewInfo);
            flow.addOnCompleteListener(task2 -> {
                // The flow has finished. The API does not indicate whether the user
                // reviewed or not, or even whether the review dialog was shown. Thus, no
                // matter the result, we continue our app flow.
            });
        } else {
            // There was some problem, continue regardless of the result.
        }
    });
}

And then you can simply call it using然后你可以简单地使用它来调用它

askRatings();

Source 来源

在此处输入图片说明

Here is my version using the BuildConfig class:这是我使用BuildConfig类的版本:

Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri);

marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
}

try {
    startActivity(marketIntent);
} catch (ActivityNotFoundException e) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID)));
}

In-App Review API is a long-awaited feature that Google has launched in August 2020 like Apple did in 2016 for iOS apps. In-App Review API 是谷歌在 2020 年 8 月推出的一项期待已久的功能,就像苹果在 2016 年为 iOS 应用推出的一样。

With this API users will review and rate an application without leaving it.使用此 API,用户无需离开即可查看和评价应用程序。 Google suggestion to developers not to force users to rate or review all the time as this API allocate a quota to each user on the specific usage of the application in a time. Google 建议开发者不要一直强迫用户评分或评论,因为此 API 会根据应用程序的特定使用情况为每个用户分配一个配额。 Surely developers would not be able to interrupt users with an attractive pop-up in the middle of their task.当然,开发人员将无法在他们的任务中间用有吸引力的弹出窗口打断用户。

Java爪哇

In Application level (build.gradle)

       dependencies {
            // This dependency from the Google Maven repository.
            // include that repository in your project's build.gradle file.
            implementation 'com.google.android.play:core:1.9.0'
        }

 

boolean isGMSAvailable = false;
int result = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
isGMSAvailable = (com.google.android.gms.common.ConnectionResult.SUCCESS == result);
  if(isGMSAvailable)
  {
    ReviewManager manager = ReviewManagerFactory.create(this);
    Task<ReviewInfo> request = manager.requestReviewFlow();
    request.addOnCompleteListener(task -> {
      try {
        if (task.isSuccessful())
        {
           // getting ReviewInfo object
            ReviewInfo reviewInfo = task.getResult();
            Task<Void> flow = manager.launchReviewFlow(this, reviewInfo);
            flow.addOnCompleteListener(task2 -> {
                // The flow has finished. The API does not indicate whether the user
                // reviewed or not, or even whether the review dialog was shown. Thus,
                // no matter the result, we continue our app flow.
                   });
        } else 
        {
            // There was some problem, continue regardless of the result
           // call old method for rating and user will land in Play Store App page
           Utils.rateOnPlayStore(this);       
        }
        } catch (Exception ex)
        {
            Log.e("review Ex", "review & rate: "+ ex);
                 }
                });
    }
    else
    {
       // if user has not installed Google play services in his/her device you land them to 
       // specific store e.g. Huawei AppGallery or Samsung Galaxy Store 
       Utils.rateOnOtherStore(this);
    }   

Kotlin科特林

val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { request ->
    if (request.isSuccessful) {
        // We got the ReviewInfo object
        val reviewInfo = request.result
    } else {
        // There was some problem, continue regardless of the result.
    }
}

//Launch the in-app review flow

val flow = manager.launchReviewFlow(activity, reviewInfo)
flow.addOnCompleteListener { _ ->
    // The flow has finished. The API does not indicate whether the user
    // reviewed or not, or even whether the review dialog was shown. Thus, no
    // matter the result, we continue our app flow.
}

for Testing use FakeReviewManager测试使用FakeReviewManager

//java
ReviewManager manager = new FakeReviewManager(this);

//Kotlin
val manager = FakeReviewManager(context)

A lot of time has passed since this answer and now THERE IS A WAY TO ATTACH THE GOOGLE PLAY REVIEW WINDOW TO YOUR APP自从这个答案以来已经过去了很多时间,现在有一种方法可以将 GOOGLE PLAY 审查窗口附加到您的应用程序

https://developer.android.com/guide/playcore/in-app-review https://developer.android.com/guide/playcore/in-app-review

// 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:core:1.10.0'

    // For Kotlin users also add the Kotlin extensions library for Play Core:
    implementation 'com.google.android.play:core-ktx:1.8.1'
    ...
}

Then whenever you want to show the rate pop-up然后每当您想显示汇率弹出窗口时

final ReviewManager manager = ReviewManagerFactory.create(context);
final Task<ReviewInfo> request = manager.requestReviewFlow();
request.addOnCompleteListener(task -> {
    if (task.isSuccessful()) {
        // We can get the ReviewInfo object
        ReviewInfo reviewInfo = task.getResult();
        Task<Void> flow = manager.launchReviewFlow(context, reviewInfo);
flow.addOnCompleteListener(task -> {
    // The flow has finished. The API does not indicate whether the user
    // reviewed or not, or even whether the review dialog was shown. Thus, no
    // matter the result, we continue our app flow.
});
    } else {
        // There was some problem, log or handle the error code.
        @ReviewErrorCode int reviewErrorCode = ((TaskException) task.getException()).getErrorCode();
    }
});

As said in the comments THE API DOESN'T LET YOU KNOW WHAT RATING THE USER GAVE正如评论中所说,API 不会让您知道用户的评分

Also google has strict guidelines to use this api, the frequency you are allowed to show the window is limited and also you are not allowed to induce the user to give you a good review.另外谷歌对这个api的使用有严格的指导,你被允许显示窗口的频率是有限的,而且你也不能诱导用户给你一个好评。 you can check the full documentation and guidelines in the link above您可以在上面的链接中查看完整的文档和指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM