我正在开发一个Android应用程序。其中一切都在正常运行。我的应用已经准备好启动了。但在这里我还需要实现一个特性。我需要显示一个包含以下内容的弹出窗口
Rate It
和Remind me later
在这里,如果任何用户在市场上对应用程序进行评分,则弹出窗口不会消失。我在谷歌上搜索了一下,找到了一个link。有了这个,我明白这是不可能知道的。所以我需要一个建议。
以前有没有人遇到过这种情况?如果是这样的话,有什么解决方案或替代方案吗?
发布于 2013-01-25 11:06:20
在某种程度上,我不久前就实现了这一点。不可能知道用户是否对应用程序进行了评分,以防止评分成为一种货币(一些开发人员可能会添加一个选项,如“对该应用程序进行评分,并在应用程序中免费获得某某”)。
我编写的类提供了三个按钮,并对对话框进行了配置,使其仅在应用程序启动n
次数后显示(如果用户之前使用过该应用程序,则有更高的机会对其进行评分。他们中的大多数甚至不太可能知道它在第一次运行时是做什么的):
public class AppRater {
private final static String APP_TITLE = "App Name";// App Name
private final static String APP_PNAME = "com.example.name";// Package Name
private final static int DAYS_UNTIL_PROMPT = 3;//Min number of days
private final static int LAUNCHES_UNTIL_PROMPT = 3;//Min number of launches
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();
}
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();
}
}
集成这个类就像添加以下内容一样简单:
AppRater.app_launched(this);
你的活动。它只需要添加到整个应用程序的一个活动中。
发布于 2014-05-29 18:12:29
我的一个使用DialogFragment:
public class RateItDialogFragment extends DialogFragment {
private static final int LAUNCHES_UNTIL_PROMPT = 10;
private static final int DAYS_UNTIL_PROMPT = 3;
private static final int MILLIS_UNTIL_PROMPT = DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000;
private static final String PREF_NAME = "APP_RATER";
private static final String LAST_PROMPT = "LAST_PROMPT";
private static final String LAUNCHES = "LAUNCHES";
private static final String DISABLED = "DISABLED";
public static void show(Context context, FragmentManager fragmentManager) {
boolean shouldShow = false;
SharedPreferences sharedPreferences = getSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
long currentTime = System.currentTimeMillis();
long lastPromptTime = sharedPreferences.getLong(LAST_PROMPT, 0);
if (lastPromptTime == 0) {
lastPromptTime = currentTime;
editor.putLong(LAST_PROMPT, lastPromptTime);
}
if (!sharedPreferences.getBoolean(DISABLED, false)) {
int launches = sharedPreferences.getInt(LAUNCHES, 0) + 1;
if (launches > LAUNCHES_UNTIL_PROMPT) {
if (currentTime > lastPromptTime + MILLIS_UNTIL_PROMPT) {
shouldShow = true;
}
}
editor.putInt(LAUNCHES, launches);
}
if (shouldShow) {
editor.putInt(LAUNCHES, 0).putLong(LAST_PROMPT, System.currentTimeMillis()).commit();
new RateItDialogFragment().show(fragmentManager, null);
} else {
editor.commit();
}
}
private static SharedPreferences getSharedPreferences(Context context) {
return context.getSharedPreferences(PREF_NAME, 0);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.rate_title)
.setMessage(R.string.rate_message)
.setPositiveButton(R.string.rate_positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getActivity().getPackageName())));
getSharedPreferences(getActivity()).edit().putBoolean(DISABLED, true).commit();
dismiss();
}
})
.setNeutralButton(R.string.rate_remind_later, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
})
.setNegativeButton(R.string.rate_never, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getSharedPreferences(getActivity()).edit().putBoolean(DISABLED, true).commit();
dismiss();
}
}).create();
}
}
然后在主FragmentActivity的onCreate()
中使用它:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
RateItDialogFragment.show(this, getFragmentManager());
}
发布于 2013-01-25 11:57:36
我认为你试图做的事情可能会适得其反。
让人们很容易地对应用程序进行评分通常是一个好主意,因为大多数人这么做是因为他们喜欢应用程序。有传言说,评级的数量会影响你的市场评级(尽管我几乎看不到这方面的证据)。通过nag屏幕对用户进行评分可能会导致人们通过留下不好的评分来清除nag。
添加直接对应用程序评分的功能导致我的免费版本的数字评分略有下降,而我的付费应用程序的评分略有增加。对于这个免费的应用程序,我的4星评级比我的5星评级增加了更多,因为那些认为我的应用程序很好但不是很好的人也开始给它打分。变化约为-0.2。对于付费用户,变化约为+0.1。我应该把它从免费版本中删除,除非我喜欢收到很多评论。
我把我的评级按钮放在设置(首选项)屏幕上,它不会影响正常操作。它仍然将我的评分提高了4到5倍。我毫不怀疑,如果我试图纠缠我的用户进行评分,我会得到很多用户给我的糟糕评分作为抗议。
https://stackoverflow.com/questions/14514579
复制相似问题