Android应用程序中“评价我的应用程序”的方法

55

有没有最佳实践方法来促使Android用户评价您的应用程序?考虑到他们可能从Amazon.com或Google市场获取它,最好的处理方式是什么,可以让用户投票?


2
最简单的方法是向您的类之一添加一个 public static final 域,表示 APK 是否适用于 Google Play、Amazon 等。根据该常量,您可以创建正确的 URI,并使用类似于我这里的库来让用户评分:https://github.com/marcow/AppRater - caw
请在手机上的Google Play商店应用程序中查看“评价此应用程序”链接。 - AlikElzin-kilaka
你可以使用库 https://github.com/Vorlonsoft/AndroidRate (implementation 'com.vorlonsoft:androidrate:1.0.3') 并设置 .setStoreType(StoreType.GOOGLEPLAY).setStoreType(StoreType.AMAZON) - Alexander Savin
9个回答

82

针对谷歌应用商店,可以查看这个整洁的代码片段。我相信你可以修改它以启动亚马逊Appstore或与之并存。

编辑:看起来该网站改变了URL结构,所以我已经更新了上面的链接,使其正常工作。在这里是一个旧副本,位于Wayback Machine,以防他们的网站再次宕机。我将在下面粘贴帖子的主要内容作为额外备份,但您仍然可能想访问链接以阅读评论并获取任何更新。

此代码会提示参与的用户在Android市场上评价您的应用程序(受iOS Appirater启发)。在评级对话框出现之前,它需要一定数量的应用启动和安装后的天数。

根据您的需求调整APP_TITLEAPP_PNAME。您还应该调整DAYS_UNTIL_PROMPTLAUNCHES_UNTIL_PROMPT

为了测试并调整对话框外观,您可以从Activity中调用AppRater.showRateDialog(this, null)。正常使用是每次调用您的活动时(例如,在onCreate方法内部),调用AppRater.app_launched(this)。如果满足所有条件,则显示对话框。

public class AppRater {
private final static String APP_TITLE = "YOUR-APP-NAME";
private final static String APP_PNAME = "YOUR-PACKAGE-NAME";

private final static int DAYS_UNTIL_PROMPT = 3;
private final static int LAUNCHES_UNTIL_PROMPT = 7;

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 dialog
    if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
        if (System.currentTimeMillis() >= date_firstLaunch + 
                (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
            showRateDialog(mContext, editor);
        }
    }

    editor.commit();
}   

public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
    final Dialog dialog = new Dialog(mContext);
    dialog.setTitle("Rate " + APP_TITLE);

    LinearLayout ll = new LinearLayout(mContext);
    ll.setOrientation(LinearLayout.VERTICAL);

    TextView tv = new TextView(mContext);
    tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
    tv.setWidth(240);
    tv.setPadding(4, 0, 4, 10);
    ll.addView(tv);

    Button b1 = new Button(mContext);
    b1.setText("Rate " + APP_TITLE);
    b1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
            dialog.dismiss();
        }
    });        
    ll.addView(b1);

    Button b2 = new Button(mContext);
    b2.setText("Remind me later");
    b2.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            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();        
    }
}

6
很棒的代码-只是需要注意,它没有设置一个标志来停止在用户点击“评价”按钮后继续提醒用户。只需将以下代码加入到评价按钮的onClick()方法中,您就可以全部设置完毕: if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } - bkurzius
2
使用AppRater.showRateDialog(YourActivity.this, null);,否则您将会得到以下错误:01-31 17:45:18.914: E/AndroidRuntime(16553): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application - Pratik Butani
2
当单击“稍后提醒”按钮时,请不要忘记清除共享首选项,以便重置所有值,并在设置的时间间隔后再次提示对话框。以下是您需要在“稍后提醒”的onClick()中放置的代码:if(editor!= null){editor.clear().commit();} - Melbourne Lopes
9
链接已失效。有人能发布一下代码吗? - user4652595
4
这个拥有58个投票却没有答案可用是不公平的。上面的链接已经失效了。:( - Madona wambua
显示剩余5条评论

38
Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
    context.startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
    UtilityClass.showAlertDialog(context, ERROR, "Couldn't launch the Google Playstore app", null, 0);
}

8
您也可以使用RateMeMaybe:https://github.com/Kopfgeldjaeger/RateMeMaybe 它提供了许多配置选项(最少几天/启动次数才会出现提示,如果用户选择“暂不评价”,下一次提示的最少天数/启动次数等),并且易于使用。
以下是README中的示例用法:
RateMeMaybe rmm = new RateMeMaybe(this);
rmm.setPromptMinimums(10, 14, 10, 30);
rmm.setDialogMessage("You really seem to like this app, "
                +"since you have already used it %totalLaunchCount% times! "
                +"It would be great if you took a moment to rate it.");
rmm.setDialogTitle("Rate this app");
rmm.setPositiveBtn("Yeeha!");
rmm.run();

编辑:如果你只想手动显示提示,你也可以使用RateMeMaybeFragment。
    if (mActivity.getSupportFragmentManager().findFragmentByTag(
            "rmmFragment") != null) {
        // the dialog is already shown to the user
        return;
    }
    RateMeMaybeFragment frag = new RateMeMaybeFragment();
    frag.setData(getIcon(), getDialogTitle(), getDialogMessage(),
            getPositiveBtn(), getNeutralBtn(), getNegativeBtn(), this);
    frag.show(mActivity.getSupportFragmentManager(), "rmmFragment");

如果您不想使用图标,可以将getIcon()替换为0;getX调用的其余部分可以替换为字符串。

更改代码以打开亚马逊市场应该很容易。


3
只需在“评价此应用程序”按钮下方编写这两行代码,即可转到您上传应用程序的Google商店页面。
String myUrl ="https://play.google.com/store/apps/details?id=smartsilencer";

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(myUrl)));

1
请不要继续以粗体的方式发布您的帖子。 - Andrew Barber
1
好的,实际上我希望用户能够快速轻松地找到他/她的解决方案。 - Pir Fahim Shah
5
楼主已经在一年前找到了解决方案。在其他人的帖子之前以加粗的方式发布“您的整个帖子”并不合适。您是否注意到自从第一次发帖以来,没有人给您点赞?而且在您添加“加粗”文本之前,这篇帖子已经被点赞了吗? - Andrew Barber

3
也许可以设置一个Facebook链接到一个粉丝页面,提供“喜欢”选项等等?在主菜单上带有小标签的图标就足够好了,不会像弹出式提醒那样让人感到烦恼。

0

Play Store政策规定,如果我们在应用程序中通知用户执行某些操作,则必须还让用户取消该操作,如果用户不想执行该操作。因此,如果我们要求用户使用“是(现在)”更新应用程序或在Play商店上评价应用程序,则我们还必须提供“否(稍后、暂不)”等选项。

rateButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
                    r.showDefaultDialog();
                }
    });

r是一个包含showDefaultDialog方法的类

public void showDefaultDialog() {

    //Log.d(TAG, "Create default dialog.");

    String title = "Enjoying Live Share Tips?";
    String loveit = "Love it";
    String likeit = "Like it";
    String hateit = "Hate it";

    new AlertDialog.Builder(hostActivity)
            .setTitle(title)
            .setIcon(R.drawable.ic_launcher)
            //.setMessage(message)
            .setPositiveButton(hateit, this)
          .setNegativeButton(loveit, this)
            .setNeutralButton(likeit, this)

            .setOnCancelListener(this)
            .setCancelable(true)
            .create().show();
}

下载完整示例[androidAone]:http://androidaone.com/11-2014/notify-users-rate-app-playstore/


1
这并没有真正回答原始问题,原始问题询问的是“最佳实践”,而不是“编写此代码”。 - HDCerberus

0

我认为,将用户重定向到您应用程序的网页是唯一的解决方案。


0

-1

无论什么情况:例如按钮

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接