是否有最佳实践方法来提示Android用户对您的应用程序进行评级?考虑到他们可以从Amazon.com或Google Marketplace获得它,以允许用户投票的方式处理此问题的最佳途径是什么?
mar*_*ica 80
对于Google Marketplace,请查看此整齐的代码段.我确信您可以修改它以启动Amazon Appstore,或者除此之外.
编辑:看起来网站改变了他们的网址结构,所以我已经更新了上面的链接,所以它现在有效.这是Wayback Machine上的旧版本,以防他们的网站再次出现故障.我将粘贴下面帖子的主要内容作为附加备份,但您仍可能需要访问该链接以阅读评论并获取任何更新.
此代码会提示用户在Android市场中为您的应用评分(受iOS Appirater启发).在评级对话框出现之前,它需要一定数量的应用程序启动和自安装以来的天数.
调整APP_TITLE和APP_PNAME您的需求.你也应该调整DAYS_UNTIL_PROMPT和LAUNCHES_UNTIL_PROMPT.
要测试它并调整对话框外观,您可以AppRater.showRateDialog(this, null)从Activity 调用.正常使用是在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();
}
}
Run Code Online (Sandbox Code Playgroud)
Moh*_*fiz 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);
}
Run Code Online (Sandbox Code Playgroud)
您也可以使用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();
Run Code Online (Sandbox Code Playgroud)
编辑:如果您只想手动显示提示,您也可以使用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");
Run Code Online (Sandbox Code Playgroud)
如果你不想使用getIcon(),可以将其替换为0; 其余的getX调用可以用字符串替换
更改代码以打开亚马逊商城应该很容易