首页 > 解决方案 > 如何在Android 10天内调用一次Play API的应用内评论?

问题描述

我实现了 Play Core Library 的应用内评论,但当我第一次打开应用时会弹出评论。

有没有办法只有在应用程序使用 10 天后才打开那个弹出框?

我已经使用此代码来实现它:

    ReviewManager manager;
    ReviewInfo reviewInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.abc);
  

        manager = ReviewManagerFactory.create(this);
        Task<ReviewInfo> request = manager.requestReviewFlow();
        request.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                // We can get the ReviewInfo object
                reviewInfo = task.getResult();
                openReview();
            }
        });
    }

    public void openReview(){
        if(reviewInfo != null){
            Task<Void> flow = manager.launchReviewFlow(this, 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.
            });
        } 

标签: javaandroidgoogle-play-core

解决方案


我会这样做:

  • 首次打开应用程序时,记录日期/时间并将其保存在SharedPreferences
  • 每次用户打开应用程序时执行当前日期/时间 - 首次打开应用程序的日期/时间。
  • 如果此值超过 10 天,则显示 IAP Review 对话框。然后您将重置存储在SharedPreferences

推荐阅读