0

我正在开发一个 Android 应用程序。我想为特定数量的启动打开一个评估器对话框。所以我使用了以下代码。

 public static void app_launched(Context mContext) {
    SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
    if (prefs.getBoolean("dontshowagain", false)) { return ; }

    SharedPreferences.Editor editor = prefs.edit();

    // Increment launch counter
    long launch_count = prefs.getLong("launch_count", 0) + 1;
    editor.putLong("launch_count", launch_count);

    // Get date of first launch
    Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
    if (date_firstLaunch == 0) {
        date_firstLaunch = System.currentTimeMillis();
        editor.putLong("date_firstlaunch", date_firstLaunch);
    }

    // Wait at least n days before opening
    if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
        if (System.currentTimeMillis() >= date_firstLaunch + 
                (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
            showRateDialog(mContext, editor);
        }
    }

    editor.commit();
}   

它工作正常。但我的问题是,如果我给 LAUNCHES_UNTIL_PROMPT 是 3,那么对话框将在第 4 次启动时出现并且用户给出他的评级,然后 5 次对话框再次启动..每次对话框启动时。所以对用户来说是很恶心的。如果用户评价了应用程序,则无需再次“评价应用程序”,直到下一个版本发布

PS:每当发布新版本的应用程序时,做一些事情来启动 apprater 是有帮助的。

4

3 回答 3

1

在对话框中包含“立即评分”、“稍后评分”和“不,谢谢”选项。如果用户单击“立即评分”,则更新首选项以不再显示对话框。如果他们点击“稍后评分”,只需重置您的计数并在另外三个启动后再次提示他们。如果“不,谢谢”,则只需更新首选项以指示不应再次显示对话框。

于 2013-05-24T06:45:03.793 回答
0

There is no way to check if a user has rated your app on Google Play, as developers may use it to incentivise certain things.

于 2013-05-24T06:57:16.900 回答
0

我前段时间找到了这个答案,并在我的一个应用程序上使用了它,并且遇到了与您相同的问题。

我建议将您的 showRateDialog 函数修改为以下内容:

    Button b1 = new Button(mContext);
    b1.setText("Rate " + APP_TITLE);
    b1.setOnClickListener(new OnClickListener() {
        // If Rate <your app> is selected, set dontshowagain field to true
        // and you will never see it again
        public void onClick(View v) {
            mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
            if (editor != null) {
                editor.putBoolean("dontshowagain", true);
                editor.commit();
            }
            dialog.dismiss();
        }
    });        
    ll.addView(b1);

    Button b2 = new Button(mContext);
    b2.setText("Remind me later");
    b2.setOnClickListener(new OnClickListener() {
        // If "Remind me later" is clicked, reset everything until requisite
        // number of launches or days since first launch
        public void onClick(View v) {
            if (editor != null) {
                editor.putLong("lLaunchCount", 0);
                editor.putLong("lDateFirstLaunch", 0);
                editor.commit();
            }
            dialog.dismiss();
        }
    });
    ll.addView(b2);

    Button b3 = new Button(mContext);
    b3.setText("No, thanks");
    b3.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (editor != null) {
                editor.putBoolean("dontshowagain", true);
                editor.commit();
            }
            dialog.dismiss();
        }
    });
    ll.addView(b3);

    dialog.setContentView(ll);        
    dialog.show();        
于 2016-05-05T13:50:57.407 回答