我想把一个“Rate This App”-链接在一个Android应用程序打开应用程序列表在用户的谷歌播放商店应用程序在他们的手机。
我需要写什么代码来创建市场://或http://-link在手机上的谷歌Play商店应用程序中打开? 你把代码放在哪里? 有人有这个的示例实现吗? 你是否必须指定market://或http:// link将被放置的屏幕,并且最好使用哪个- market://或http://?
我想把一个“Rate This App”-链接在一个Android应用程序打开应用程序列表在用户的谷歌播放商店应用程序在他们的手机。
我需要写什么代码来创建市场://或http://-link在手机上的谷歌Play商店应用程序中打开? 你把代码放在哪里? 有人有这个的示例实现吗? 你是否必须指定market://或http:// link将被放置的屏幕,并且最好使用哪个- market://或http://?
当前回答
从现在开始,你可以使用谷歌的应用评级功能。
这里是Kotlin/Java集成的官方指南
谷歌Play In-App Review API允许您提示用户提交Play Store评级和评论,而无需离开您的应用程序或游戏。 通常,应用内部审查流程(见图1)可以在 在你的应用程序的用户旅程的任何时间 用户可以使用1到5星系统对你的应用进行评级 添加可选注释。一旦提交,审查将被发送到 播放商店和最终显示。
其他回答
下面是我使用BuildConfig类的版本:
Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri);
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
}
try {
startActivity(marketIntent);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID)));
}
Play Store评分
btn_rate_us.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
// To count with Play market backstack, After pressing back button,
// to taken back to our application, we need to add following flags to intent.
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
}
}
});
我用以下代码从我的应用程序打开Play Store:
val uri: Uri = Uri.parse("market://details?id=$packageName")
val goToMarket = Intent(Intent.ACTION_VIEW, uri)
// To count with Play market backstack, After pressing back button,
// to taken back to our application, we need to add following flags to intent.
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or
Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
try {
startActivity(goToMarket)
} catch (e: ActivityNotFoundException) {
startActivity(Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=$packageName")))
}
选项2: 是使用resolveActivity而不是try. catch
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
} else {
openUrl();
}
Java解决方案(2020年谷歌发布的应用程序内审查API):
您现在可以使用谷歌提供的应用程序审查API开箱即用。
首先,在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'
}
将此方法添加到您的活动中:
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解决方案(2020年谷歌发布应用程序内评论API):
您现在可以使用谷歌提供的应用程序审查API开箱即用。
首先,在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'
implementation 'com.google.android.play:core-ktx:1.8.1'
}
创建一个方法,并把下面的代码放在里面:
val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { request ->
if (request.isSuccessful) {
// We got the ReviewInfo object
val reviewInfo = request.result
val flow = manager.launchReviewFlow(activity, reviewInfo)
flow.addOnCompleteListener { _ ->
// 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.
}
}
源