有没有最佳实践方法来促使Android用户评价您的应用程序?考虑到他们可能从Amazon.com或Google市场获取它,最好的处理方式是什么,可以让用户投票?
针对谷歌应用商店,可以查看这个整洁的代码片段。我相信你可以修改它以启动亚马逊Appstore或与之并存。
编辑:看起来该网站改变了URL结构,所以我已经更新了上面的链接,使其正常工作。在这里是一个旧副本,位于Wayback Machine,以防他们的网站再次宕机。我将在下面粘贴帖子的主要内容作为额外备份,但您仍然可能想访问链接以阅读评论并获取任何更新。
此代码会提示参与的用户在Android市场上评价您的应用程序(受iOS Appirater启发)。在评级对话框出现之前,它需要一定数量的应用启动和安装后的天数。
根据您的需求调整APP_TITLE
和APP_PNAME
。您还应该调整DAYS_UNTIL_PROMPT
和LAUNCHES_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();
}
}
if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); }
- bkurziusAppRater.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 ButaniUri 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);
}
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();
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调用的其余部分可以替换为字符串。
更改代码以打开亚马逊市场应该很容易。
String myUrl ="https://play.google.com/store/apps/details?id=smartsilencer";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(myUrl)));
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/
我认为,将用户重定向到您应用程序的网页是唯一的解决方案。
对于简单的解决方案,请尝试使用这个库https://github.com/kobakei/Android-RateThisApp
您还可以更改其配置,例如显示对话框的标准、标题、消息等。
无论什么情况:例如按钮
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData
(Uri.parse("market://details?id="+context.getPackageName()));
startActivity(intent);
public static final
域,表示 APK 是否适用于 Google Play、Amazon 等。根据该常量,您可以创建正确的 URI,并使用类似于我这里的库来让用户评分:https://github.com/marcow/AppRater - cawimplementation 'com.vorlonsoft:androidrate:1.0.3'
) 并设置.setStoreType(StoreType.GOOGLEPLAY)
或.setStoreType(StoreType.AMAZON)
。 - Alexander Savin