【问题标题】:Android approach for "Rate my application" [closed]“评价我的应用程序”的 Android 方法 [关闭]
【发布时间】:2011-06-26 07:46:19
【问题描述】:

是否有提示 Android 用户对您的应用程序进行评分的最佳做法?考虑到他们可以从 Amazon.com 或 Google Marketplace 获得它,以允许用户投票的方式处理此问题的最佳途径是什么?

【问题讨论】:

  • 最简单的方法是在您的一个类中添加一个public static final 字段,指示 APK 是否适用于 Google Play、Amazon 等。基于该常量,您可以创建正确的 URI 并使用像我这样的图书馆让用户评价:github.com/marcow/AppRater
  • 您可以将库github.com/Vorlonsoft/AndroidRate (implementation 'com.vorlonsoft:androidrate:1.0.3') 与.setStoreType(StoreType.GOOGLEPLAY).setStoreType(StoreType.AMAZON) 一起使用

标签: android rate


【解决方案1】:

对于 Google Marketplace,看看这个简洁的code snippet。我相信您可以修改它以启动 Amazon Appstore 来替代或补充。

编辑: 看起来该网站更改了它们的 URL 结构,所以我更新了上面的链接,现在它可以工作了。这是Wayback Machine 的旧副本,以防他们的网站再次出现故障。我将粘贴下面帖子的主要内容作为附加备份,但您仍可能希望访问该链接以阅读 cmets 并获取任何更新。

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

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

要对其进行测试并调整对话框外观,您可以从 Activity 中调用 AppRater.showRateDialog(this, null)。正常使用是在每次调用活动时调用AppRater.app_launched(this)(例如,从 onCreate 方法中)。如果满足所有条件,则会出现对话框。

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();        
    }
}

【讨论】:

  • 很棒的代码 - 请注意,一旦用户单击“评分”按钮,它不会设置停止提醒用户的标志。只需将其添加到速率按钮的 onClick() 中,您就应该一切就绪:if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); }
  • 使用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
  • 点击“稍后提醒我”按钮时不要忘记清除共享首选项,以便重置所有值,以便在设置间隔后再次提示对话框。这是您需要放入“稍后提醒我”的 onClick() 的代码 if (editor != null) {editor.clear().commit();}
  • 链接已关闭。有人可以发布代码吗?
  • 获得 58 票而没有答案是不公平的。上面的链接坏了。 :(
【解决方案2】:
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);
}

【讨论】:

    【解决方案3】:

    您也可以使用 RateMeMaybe:https://github.com/Kopfgeldjaeger/RateMeMaybe

    它为您提供了相当多的配置选项(最少天数/启动到第一个提示,最少天数/启动到每个下一个提示,如果用户选择“不是现在”,对话框标题,消息等)。它也很容易使用。

    自述文件中的示例用法:

    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 调用可以用字符串替换

    更改代码以打开亚马逊商城应该很容易

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

        只需在“对此应用排名”按钮下编写这两行代码,它就会将您带到您上传应用的 Google 商店。

        String myUrl ="https://play.google.com/store/apps/details?id=smartsilencer";
        
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(myUrl)));
        

        【讨论】:

        • 请不要继续用粗体这样的全文来发帖。
        • 好的,其实我希望 dt 用户可以轻松快速地找到他/她的解决方案,
        • OP 在一年前就找到了他们的解决方案。以粗体发布您的整个帖子以试图使其在其他人的帖子之前被看到是完全不合适的。您是否注意到自从您的前两个帖子以来没有人对您的帖子进行投票?而这一个在您添加“粗体”文本之前被投票赞成?
        【解决方案6】:

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

        【讨论】:

          【解决方案7】:

          Play 商店政策规定,如果我们通知用户在我们的应用中执行某些操作,那么如果用户不想执行该操作,我们还必须让用户取消该操作。因此,如果我们要求用户更新应用或在 Play 商店中使用 Yes(Now) 对应用评分,那么我们还必须提供 No(Later, Not Now) 等选项。

          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/

          【讨论】:

          • 这并没有真正回答最初的问题,即“最佳实践”而不是“执行此操作的代码”。
          【解决方案8】:

          对于简单的解决方案,试试这个库 https://github.com/kobakei/Android-RateThisApp

          您还可以更改其配置,例如显示对话框、标题、消息的条件

          【讨论】:

            【解决方案9】:

            无论如何:例如按钮

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

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2012-01-24
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多