我正在开发一个Android应用程序。在其中一切正常。我的应用已准备好启动。但是我需要实现另一个功能。我需要显示一个包含以下内容的弹出窗口
Rate It
和 Remind me later
在这里,如果有任何用户对市场上的应用程序进行评分,则弹出窗口不会消失。我已经在Google中搜索并找到一个链接。据此,我知道这是不可能知道的。所以我需要一个建议。
有人遇到过这种情况吗?如果是这样,是否有解决方案或替代方案?
我正在开发一个Android应用程序。在其中一切正常。我的应用已准备好启动。但是我需要实现另一个功能。我需要显示一个包含以下内容的弹出窗口
Rate It
和 Remind me later
在这里,如果有任何用户对市场上的应用程序进行评分,则弹出窗口不会消失。我已经在Google中搜索并找到一个链接。据此,我知道这是不可能知道的。所以我需要一个建议。
有人遇到过这种情况吗?如果是这样,是否有解决方案或替代方案?
Mar 15 2011
。所以差不多20个月了。我认为有人可以为我的要求提供解决方案或替代方案。那是yi张贴在这里。
implementation 'com.vorlonsoft:androidrate:1.0.3'
)
Answers:
我在某种程度上实现了这一点。不可能知道用户是否对应用程序进行了评级,以防止评级成为一种货币(某些开发人员可能会添加“为该应用程序评级并免费获得该应用程序等”之类的选项)。
我编写的课程提供了三个按钮,并配置了对话框,以便仅在应用启动后显示该对话框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);
为了你的活动。只需将其添加到整个应用程序的一个活动中即可。
apprater
在身份验证后显示对话框并更改shared preference
为在中包含google电子邮件地址来处理key
。
AppRater.app_launched(this);
我的内onCreate()
MainActivity的。我还将最低启动次数更改为2。但是,启动2个应用程序后,我没有看到对话框。你能帮我吗?谢谢!
Context.MODE_PRIVATE
-– context.getSharedPreferences("apprater", Context.MODE_PRIVATE);
我的一个使用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();
}
}
然后在onCreate()
您的主要FragmentActivity中使用它:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
RateItDialogFragment.show(this, getFragmentManager());
}
setPositiveButton
和中仔细注意到setNegativeButton
,它将使用commit写入共享的首选项,但是如果您使用apply异步,它将保留对活动的引用,直到活动完成为止,然后立即调用dismiss。Dismiss会尝试破坏该片段,但不能这样做,因为该活动是由共享首选项应用程序进程保留/使用的。(我之所以这样做,是因为AndroidStudio会提示用户更改要应用的提交,除非您使用其他逻辑)
我认为您尝试做的事可能适得其反。
通常,让人们容易对应用程序进行评分是个好主意,因为大多数人因为喜欢应用程序而费心地这样做。有传言说,评级数量会影响您的市场评级(尽管我看不到任何证据)。通过nag屏幕使用户陷入等级评定中很可能会导致人们通过留下差评来清除nag。
添加对应用程序直接评分的功能导致我的免费版本的数字评分略有下降,而付费应用程序则略有增加。对于免费应用程序,由于认为我的应用程序不错但不太好的人也开始对它进行评分,因此我的4星评分增加了超过5星评分。变化约为-0.2。对于付费用户,零钱约为+0.1。我应该将其从免费版本中删除,但我喜欢收到很多评论。
我将评级按钮放入设置(首选项)屏幕,在此不影响正常操作。它仍然使我的评分率提高了4或5倍。毫无疑问,如果我试图诱使用户进行评分,我会得到很多用户的不满意,以示抗议。
AndroidRate是一个库,可通过提示用户在使用几天后对其进行评分来帮助您推广android应用。
模块摇篮:
dependencies {
implementation 'com.vorlonsoft:androidrate:1.0.8'
}
MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AppRate.with(this)
.setStoreType(StoreType.GOOGLEPLAY) //default is GOOGLEPLAY (Google Play), other options are
// AMAZON (Amazon Appstore) and
// SAMSUNG (Samsung Galaxy Apps)
.setInstallDays((byte) 0) // default 10, 0 means install day
.setLaunchTimes((byte) 3) // default 10
.setRemindInterval((byte) 2) // default 1
.setRemindLaunchTimes((byte) 2) // default 1 (each launch)
.setShowLaterButton(true) // default true
.setDebug(false) // default false
//Java 8+: .setOnClickButtonListener(which -> Log.d(MainActivity.class.getName(), Byte.toString(which)))
.setOnClickButtonListener(new OnClickButtonListener() { // callback listener.
@Override
public void onClickButton(byte which) {
Log.d(MainActivity.class.getName(), Byte.toString(which));
}
})
.monitor();
if (AppRate.with(this).getStoreType() == StoreType.GOOGLEPLAY) {
//Check that Google Play is available
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) != ConnectionResult.SERVICE_MISSING) {
// Show a dialog if meets conditions
AppRate.showRateDialogIfMeetsConditions(this);
}
} else {
// Show a dialog if meets conditions
AppRate.showRateDialogIfMeetsConditions(this);
}
}
显示速率对话框的默认条件如下:
AppRate#setInstallDays(byte)
。AppRate#setLaunchTimes(byte)
。AppRate#setRemindInterval(byte)
。AppRate#setRemindLaunchTimes(byte)
。通过更改。setShowLaterButton(boolean)
。DialogInterface.OnClickListener#onClick
将传递到的参数中onClickButton
。AppRate#setDebug(boolean)
将确保每次启动应用程序时都会显示评级请求。此功能仅用于开发!。您可以添加其他可选要求以显示对话框。每个需求可以作为唯一字符串添加/引用。您可以为每个此类事件设置最小计数(例如,“ action_performed” 3次,“ button_clicked” 5次等)
AppRate.with(this).setMinimumEventCount(String, short);
AppRate.with(this).incrementEventCount(String);
AppRate.with(this).setEventCountValue(String, short);
当您想再次显示对话框时,请致电AppRate#clearAgreeShowDialog()
。
AppRate.with(this).clearAgreeShowDialog();
打电话AppRate#showRateDialog(Activity)
。
AppRate.with(this).showRateDialog(this);
打电话AppRate#setView(View)
。
LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.custom_dialog, (ViewGroup)findViewById(R.id.layout_root));
AppRate.with(this).setView(view).monitor();
您可以使用特定主题来扩大对话框。
AppRate.with(this).setThemeResId(int);
如果要使用自己的对话框标签,请在应用程序上覆盖字符串xml资源。
<resources>
<string name="rate_dialog_title">Rate this app</string>
<string name="rate_dialog_message">If you enjoy playing this app, would you mind taking a moment to rate it? It won\'t take more than a minute. Thanks for your support!</string>
<string name="rate_dialog_ok">Rate It Now</string>
<string name="rate_dialog_cancel">Remind Me Later</string>
<string name="rate_dialog_no">No, Thanks</string>
</resources>
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) != ConnectionResult.SERVICE_MISSING) {
}
使用这个库,很简单。.https ://github.com/hotchemi/Android-Rate
通过添加依赖项。
dependencies {
compile 'com.github.hotchemi:android-rate:0.5.6'
}
implementation 'com.vorlonsoft:androidrate:1.0.3'
)。是最新的。
此解决方案与上面介绍的解决方案非常相似。唯一的区别是,您将能够在每次启动和每天延迟一次“等级”对话框的提示。如果按下“稍后提醒我”按钮,则我将弹出窗口延迟3天并启动10次。对于选择评分的人也是如此,但是延迟时间更长(如果用户对应用进行了实际评分,请不要太快打扰用户。可以将其更改为不再显示,那么您必须将代码更改为您喜欢的代码)。希望对您有所帮助!
public class AppRater {
private final static String APP_TITLE = "your_app_name";
private static String PACKAGE_NAME = "your_package_name";
private static int DAYS_UNTIL_PROMPT = 5;
private static int LAUNCHES_UNTIL_PROMPT = 10;
private static long EXTRA_DAYS;
private static long EXTRA_LAUCHES;
private static SharedPreferences prefs;
private static SharedPreferences.Editor editor;
private static Activity activity;
public static void app_launched(Activity activity1) {
activity = activity1;
Configs.sendScreenView("Avaliando App", activity);
PACKAGE_NAME = activity.getPackageName();
prefs = activity.getSharedPreferences("apprater", Context.MODE_PRIVATE);
if (prefs.getBoolean("dontshowagain", false))
return;
editor = prefs.edit();
EXTRA_DAYS = prefs.getLong("extra_days", 0);
EXTRA_LAUCHES = prefs.getLong("extra_launches", 0);
// 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 + EXTRA_LAUCHES))
if (System.currentTimeMillis() >= date_firstLaunch + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000) + EXTRA_DAYS)
showRateDialog();
editor.commit();
}
public static void showRateDialog() {
final Dialog dialog = new Dialog(activity);
dialog.setTitle("Deseja avaliar o aplicativo " + APP_TITLE + "?");
LinearLayout ll = new LinearLayout(activity);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setPadding(5, 5, 5, 5);
TextView tv = new TextView(activity);
tv.setTextColor(activity.getResources().getColor(R.color.default_text));
tv.setText("Ajude-nos a melhorar o aplicativo com sua avaliação no Google Play!");
tv.setWidth(240);
tv.setGravity(Gravity.CENTER);
tv.setPadding(5, 5, 5, 5);
ll.addView(tv);
Button b1 = new Button(activity);
b1.setTextColor(activity.getResources().getColor(R.color.default_text));
b1.setBackground(activity.getResources().getDrawable(R.drawable.rounded_blue_box));
b1.setTextColor(Color.WHITE);
b1.setText("Avaliar aplicativo " + APP_TITLE + "!");
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Configs.sendHitEvents(Configs.APP_RATER, Configs.CATEGORIA_ANALYTICS, "Clique", "Avaliar", activity);
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + PACKAGE_NAME)));
delayDays(60);
delayLaunches(30);
dialog.dismiss();
}
});
ll.addView(b1);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) b1.getLayoutParams();
params.setMargins(5, 3, 5, 3);
b1.setLayoutParams(params);
Button b2 = new Button(activity);
b2.setTextColor(activity.getResources().getColor(R.color.default_text));
b2.setBackground(activity.getResources().getDrawable(R.drawable.rounded_blue_box));
b2.setTextColor(Color.WHITE);
b2.setText("Lembre-me mais tarde!");
b2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Configs.sendHitEvents(Configs.APP_RATER, Configs.CATEGORIA_ANALYTICS, "Clique", "Avaliar Mais Tarde", activity);
delayDays(3);
delayLaunches(10);
dialog.dismiss();
}
});
ll.addView(b2);
params = (LinearLayout.LayoutParams) b2.getLayoutParams();
params.setMargins(5, 3, 5, 3);
b2.setLayoutParams(params);
Button b3 = new Button(activity);
b3.setTextColor(activity.getResources().getColor(R.color.default_text));
b3.setBackground(activity.getResources().getDrawable(R.drawable.rounded_blue_box));
b3.setTextColor(Color.WHITE);
b3.setText("Não, obrigado!");
b3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Configs.sendHitEvents(Configs.APP_RATER, Configs.CATEGORIA_ANALYTICS, "Clique", "Não Avaliar", activity);
if (editor != null) {
editor.putBoolean("dontshowagain", true);
editor.commit();
}
dialog.dismiss();
}
});
ll.addView(b3);
params = (LinearLayout.LayoutParams) b3.getLayoutParams();
params.setMargins(5, 3, 5, 0);
b3.setLayoutParams(params);
dialog.setContentView(ll);
dialog.show();
}
private static void delayLaunches(int numberOfLaunches) {
long extra_launches = prefs.getLong("extra_launches", 0) + numberOfLaunches;
editor.putLong("extra_launches", extra_launches);
editor.commit();
}
private static void delayDays(int numberOfDays) {
Long extra_days = prefs.getLong("extra_days", 0) + (numberOfDays * 1000 * 60 * 60 * 24);
editor.putLong("extra_days", extra_days);
editor.commit();
}
}
按钮具有特定的颜色和背景。背景如以下xml文件所示:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#2E78B9" />
<corners
android:bottomLeftRadius="6dp"
android:bottomRightRadius="6dp"
android:topLeftRadius="6dp"
android:topRightRadius="6dp" />
</shape>
我正在使用这个简单的解决方案。您可以使用gradle添加该库:https : //github.com/fernandodev/easy-rating-dialog
compile 'com.github.fernandodev.easyratingdialog:easyratingdialog:+'
从链接的其他帖子中可以看出,该应用无法通过某种方式知道用户是否发表了评论。并且有充分的理由。
考虑一下,如果应用程序可以判断用户是否留下了评论,则开发人员可以限制某些功能,这些功能只有在用户留下5/5评分时才能解锁。这将导致Google Play的其他用户不信任评论,并破坏评分系统。
我所看到的替代解决方案是,只要该应用打开特定的次数或设置的间隔,该应用就会提醒用户提交评级。例如,每隔10次打开该应用程序,要求用户留下一个评分并提供“已完成”和“稍后提醒我”按钮。如果用户选择稍后提醒他/她,请继续显示此消息。其他一些应用程序开发人员会以递增的间隔显示此消息(例如,打开应用程序的第5、10、15n次),因为例如,如果用户在打开应用程序的第100次时没有留下评论,他/她很可能不会离开。
这个解决方案并不完美,但我认为这是目前最好的解决方案。它的确使您信任用户,但要意识到,替代方案对于应用程序市场中的每个人都意味着潜在的更糟的体验。
首先,在build.gradle(app)
文件中添加以下依赖项(此处完整设置)
dependencies {
// This dependency is downloaded from the Google’s Maven repository.
// So, make sure you also include that repository in your project's build.gradle file.
implementation 'com.google.android.play:core:1.8.0'
}
将此方法添加到您的Activity
:
void askRatings() {
ReviewManager manager = ReviewManagerFactory.create(this);
Task<ReviewInfo> request = manager.requestReviewFlow();
request.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
// We can get the ReviewInfo object
ReviewInfo reviewInfo = task.getResult();
Task<Void> flow = manager.launchReviewFlow(this, reviewInfo);
flow.addOnCompleteListener(task2 -> {
// The flow has finished. The API does not indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, we continue our app flow.
});
} else {
// There was some problem, continue regardless of the result.
}
});
}
像其他任何方法一样调用它:
askRatings();
Kotlin代码可以在这里找到
Kotlin版本的Raghav Sood的答案
评分者
class Rater {
companion object {
private const val APP_TITLE = "App Name"
private const val APP_NAME = "com.example.name"
private const val RATER_KEY = "rater_key"
private const val LAUNCH_COUNTER_KEY = "launch_counter_key"
private const val DO_NOT_SHOW_AGAIN_KEY = "do_not_show_again_key"
private const val FIRST_LAUNCH_KEY = "first_launch_key"
private const val DAYS_UNTIL_PROMPT: Int = 3
private const val LAUNCHES_UNTIL_PROMPT: Int = 3
fun start(mContext: Context) {
val prefs: SharedPreferences = mContext.getSharedPreferences(RATER_KEY, 0)
if (prefs.getBoolean(DO_NOT_SHOW_AGAIN_KEY, false)) {
return
}
val editor: Editor = prefs.edit()
val launchesCounter: Long = prefs.getLong(LAUNCH_COUNTER_KEY, 0) + 1;
editor.putLong(LAUNCH_COUNTER_KEY, launchesCounter)
var firstLaunch: Long = prefs.getLong(FIRST_LAUNCH_KEY, 0)
if (firstLaunch == 0L) {
firstLaunch = System.currentTimeMillis()
editor.putLong(FIRST_LAUNCH_KEY, firstLaunch)
}
if (launchesCounter >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= firstLaunch +
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)
) {
showRateDialog(mContext, editor)
}
}
editor.apply()
}
fun showRateDialog(mContext: Context, editor: Editor) {
Dialog(mContext).apply {
setTitle("Rate $APP_TITLE")
val ll = LinearLayout(mContext)
ll.orientation = LinearLayout.VERTICAL
TextView(mContext).apply {
text =
"If you enjoy using $APP_TITLE, please take a moment to rate it. Thanks for your support!"
width = 240
setPadding(4, 0, 4, 10)
ll.addView(this)
}
Button(mContext).apply {
text = "Rate $APP_TITLE"
setOnClickListener {
mContext.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$APP_NAME")
)
);
dismiss()
}
ll.addView(this)
}
Button(mContext).apply {
text = "Remind me later"
setOnClickListener {
dismiss()
};
ll.addView(this)
}
Button(mContext).apply {
text = "No, thanks"
setOnClickListener {
editor.putBoolean(DO_NOT_SHOW_AGAIN_KEY, true);
editor.commit()
dismiss()
};
ll.addView(this)
}
setContentView(ll)
show()
}
}
}
}
优化答案
评分者
class Rater {
companion object {
fun start(context: Context) {
val prefs: SharedPreferences = context.getSharedPreferences(RATER_KEY, 0)
if (prefs.getBoolean(DO_NOT_SHOW_AGAIN_KEY, false)) {
return
}
val editor: Editor = prefs.edit()
val launchesCounter: Long = prefs.getLong(LAUNCH_COUNTER_KEY, 0) + 1;
editor.putLong(LAUNCH_COUNTER_KEY, launchesCounter)
var firstLaunch: Long = prefs.getLong(FIRST_LAUNCH_KEY, 0)
if (firstLaunch == 0L) {
firstLaunch = System.currentTimeMillis()
editor.putLong(FIRST_LAUNCH_KEY, firstLaunch)
}
if (launchesCounter >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= firstLaunch +
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)
) {
showRateDialog(context, editor)
}
}
editor.apply()
}
fun showRateDialog(context: Context, editor: Editor) {
Dialog(context).apply {
setTitle("Rate $APP_TITLE")
LinearLayout(context).let { layout ->
layout.orientation = LinearLayout.VERTICAL
setDescription(context, layout)
setPositiveAnswer(context, layout)
setNeutralAnswer(context, layout)
setNegativeAnswer(context, editor, layout)
setContentView(layout)
show()
}
}
}
private fun setDescription(context: Context, layout: LinearLayout) {
TextView(context).apply {
text = context.getString(R.string.rate_description, APP_TITLE)
width = 240
setPadding(4, 0, 4, 10)
layout.addView(this)
}
}
private fun Dialog.setPositiveAnswer(
context: Context,
layout: LinearLayout
) {
Button(context).apply {
text = context.getString(R.string.rate_now)
setOnClickListener {
context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.market_uri, APP_NAME))
)
);
dismiss()
}
layout.addView(this)
}
}
private fun Dialog.setNeutralAnswer(
context: Context,
layout: LinearLayout
) {
Button(context).apply {
text = context.getString(R.string.remind_later)
setOnClickListener {
dismiss()
};
layout.addView(this)
}
}
private fun Dialog.setNegativeAnswer(
context: Context,
editor: Editor,
layout: LinearLayout
) {
Button(context).apply {
text = context.getString(R.string.no_thanks)
setOnClickListener {
editor.putBoolean(DO_NOT_SHOW_AGAIN_KEY, true);
editor.commit()
dismiss()
};
layout.addView(this)
}
}
}
}
常数
object Constants {
const val APP_TITLE = "App Name"
const val APP_NAME = "com.example.name"
const val RATER_KEY = "rater_key"
const val LAUNCH_COUNTER_KEY = "launch_counter_key"
const val DO_NOT_SHOW_AGAIN_KEY = "do_not_show_again_key"
const val FIRST_LAUNCH_KEY = "first_launch_key"
const val DAYS_UNTIL_PROMPT: Int = 3
const val LAUNCHES_UNTIL_PROMPT: Int = 3
}
strings.xml
<resources>
<string name="rate_description">If you enjoy using %1$s, please take a moment to rate it. Thanks for your support!</string>
<string name="rate_now">Rate now</string>
<string name="no_thanks">No, thanks</string>
<string name="remind_later">Remind me later</string>
<string name="market_uri">market://details?id=%1$s</string>
</resources>
Android推出了新的应用内评论系统,开发人员可以在不离开应用程序的情况下要求Play商店评论。
要查看设计指南以及何时显示评论卡,请参阅正式文档
实现:
implementation 'com.google.android.play:core:1.8.0'
创建一个ReviewManager实例并请求ReviewInfo对象。要预先缓存的ReviewInfo对象,然后可以触发“ launchReviewFlow”以向用户出示Review卡。
private var reviewInfo: ReviewInfo? = null
val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
requestFlow.addOnCompleteListener { request ->
if (request.isSuccessful) {
//Received ReviewInfo object
reviewInfo = request.result
} else {
//Problem in receiving object
reviewInfo = null
}
reviewInfo?.let {
val flow = reviewManager.launchReviewFlow(this@MainActivity, it)
flow.addOnCompleteListener {
//Irrespective of the result, the app flow should continue
}
}
注意:建议在用户对您的应用或游戏进行足够的体验后显示评论流程。
何时要求进行应用内审核:
测试此之前的几点:
在测试新功能时,大多数情况下,我们会创建一个新项目,该项目将具有新的ApplicationId,请确保提供的Play商店中已发布并可用的ApplicationId。
如果您过去曾对自己的应用提供过反馈,则应用内评论API的launchReviewFlow将不会显示任何评论卡。它只是触发一个成功事件。
由于配额限制,调用launchReviewFlow方法可能并不总是显示对话框。它不应与任何点击事件链接。
确保为应用内评论实施以下内容:
implementation 'com.google.android.play:core:1.8.0'
OnCreate
public void RateApp(Context mContext) {
try {
ReviewManager manager = ReviewManagerFactory.create(mContext);
manager.requestReviewFlow().addOnCompleteListener(new OnCompleteListener<ReviewInfo>() {
@Override
public void onComplete(@NonNull Task<ReviewInfo> task) {
if(task.isSuccessful()){
ReviewInfo reviewInfo = task.getResult();
manager.launchReviewFlow((Activity) mContext, reviewInfo).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(mContext, "Rating Failed", Toast.LENGTH_SHORT).show();
}
}).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(mContext, "Review Completed, Thank You!", Toast.LENGTH_SHORT).show();
}
});
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(mContext, "In-App Request Failed", Toast.LENGTH_SHORT).show();
}
});
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
所有这些库都不是本文中解决该问题的方法。该库仅打开Google Play上该应用程序的网页。相反,此Play核心库具有更一致的接口。
所以我认为这就是问题,ProGuard:它足以掩盖某些类 https://stackoverflow.com/a/63650212/10117882