提示用户对应用内的Android应用进行评分

caw*_*caw 30 android user-input voting rating

在我的Android应用程序中,我想在某个时间点提示用户对Android市场中的应用进行评级.

在搜索了一种方法之后,我在这个网站上找到了一些代码.这段代码似乎运行得很好.

但遗憾的是,当Android市场未安装在用户的手机上时,此代码似乎会引发"强制关闭"错误消息.有没有办法检查Android市场是否已安装,如果没有,请不要尝试执行代码?

引发错误的行可能就是这个,因为它无法解析URI:

mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
Run Code Online (Sandbox Code Playgroud)

顺便说一下,那个代码还有其他可以改进的东西吗?

编辑:

几年后,我将所有代码放入一个小型库项目:GitHub上的AppRater

xba*_*esx 36

这是您需要的所有代码,(Kurt的答案和推断信息的集合,以及链接和问题):

/* This code assumes you are inside an activity */
final Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);

if (getPackageManager().queryIntentActivities(rateAppIntent, 0).size() > 0)
{
    startActivity(rateAppIntent);
}
else
{
    /* handle your error case: the device has no way to handle market urls */
}
Run Code Online (Sandbox Code Playgroud)


Kur*_*aum 14

您始终可以从PackageManager类调用getInstalledPackages()并检查以确保安装了市场类.您还可以使用queryIntentActivities()来确保您构造的Intent能够被某些东西处理,即使它不是市场应用程序.这可能是最好的事情,因为它最灵活和最强大.


Kop*_*ger 9

您也可以使用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)


DiR*_*oiD 5

首先,您需要计算应用程序的使用次数;

SharedPreferences preferences = getSharedPreferences("progress", MODE_PRIVATE);
int appUsedCount = preferences.getInt("appUsedCount",0);
appUsedCount++;
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("appUsedCount", appUsedCount);
editor.apply();

if (appUsedCount==10 || appUsedCount==50 || appUsedCount==100 || appUsedCount==200 || appUsedCount==300){
    AskForRating(appUsedCount);
} else {
    finish();
}
Run Code Online (Sandbox Code Playgroud)

比你能这样提示;

private void AskForRating(int _appUsedCount){

    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Please Rate Us");
    alert.setIcon(R.drawable.book);
    alert.setMessage("Thanks for using the application. If you like YOUR APP NAME please rate us! Your feedback is important for us!");
    alert.setPositiveButton("Rate it",new Dialog.OnClickListener(){
        public void onClick(DialogInterface dialog, int whichButton){
            String url = "https://play.google.com/store/apps/details?id=YOUR PACKAGE NAME";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });
    alert.setNegativeButton("Not now", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });
    alert.show();
}
Run Code Online (Sandbox Code Playgroud)