我想把一个“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星系统对你的应用进行评级 添加可选注释。一旦提交,审查将被发送到 播放商店和最终显示。
其他回答
应用程序内评论API是谷歌在2020年8月推出的一个期待已久的功能,就像苹果在2016年为iOS应用程序推出的功能一样。
有了这个API,用户不用离开就可以对应用程序进行审查和评分。谷歌建议开发人员不要强迫用户一直进行评分或审查,因为这个API在一段时间内为每个用户分配了应用程序的特定使用配额。开发人员当然不能在他们的任务中间用一个诱人的弹出窗口打断用户。
Java
In Application level (build.gradle)
dependencies {
// This dependency from the Google Maven repository.
// include that repository in your project's build.gradle file.
implementation 'com.google.android.play:core:1.9.0'
}
boolean isGMSAvailable = false;
int result = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
isGMSAvailable = (com.google.android.gms.common.ConnectionResult.SUCCESS == result);
if(isGMSAvailable)
{
ReviewManager manager = ReviewManagerFactory.create(this);
Task<ReviewInfo> request = manager.requestReviewFlow();
request.addOnCompleteListener(task -> {
try {
if (task.isSuccessful())
{
// getting 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
// call old method for rating and user will land in Play Store App page
Utils.rateOnPlayStore(this);
}
} catch (Exception ex)
{
Log.e("review Ex", "review & rate: "+ ex);
}
});
}
else
{
// if user has not installed Google play services in his/her device you land them to
// specific store e.g. Huawei AppGallery or Samsung Galaxy Store
Utils.rateOnOtherStore(this);
}
科特林
val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { request ->
if (request.isSuccessful) {
// We got the ReviewInfo object
val reviewInfo = request.result
} else {
// There was some problem, continue regardless of the result.
}
}
//Launch the in-app review flow
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.
}
对于测试使用FakeReviewManager
//java
ReviewManager manager = new FakeReviewManager(this);
//Kotlin
val manager = FakeReviewManager(context)
一个kotlin版本
fun openAppInPlayStore() {
val uri = Uri.parse("market://details?id=" + context.packageName)
val goToMarketIntent = Intent(Intent.ACTION_VIEW, uri)
var flags = Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
flags = if (Build.VERSION.SDK_INT >= 21) {
flags or Intent.FLAG_ACTIVITY_NEW_DOCUMENT
} else {
flags or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
goToMarketIntent.addFlags(flags)
try {
startActivity(context, goToMarketIntent, null)
} catch (e: ActivityNotFoundException) {
val intent = Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName))
startActivity(context, intent, null)
}
}
在你的活动类中声明一个方法。然后复制并粘贴下面的代码。
private void OpenAppInPlayStore(){
Uri uri = Uri.parse("market://details?id=" + this.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=" + this.getPackageName())));
}
}
现在从代码的任何地方调用这个方法。
下面的图片来自我的实际项目。
前提是你同时在谷歌Play Store和Amazon Appstore发布应用。我还处理过用户(尤其是中国用户)既没有应用商店又没有浏览器的情况。
public void goToMyApp(boolean googlePlay) {//true if Google Play, false if Amazone Store
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "market://details?id=" : "amzn://apps/android?p=") +getPackageName())));
} catch (ActivityNotFoundException e1) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "http://play.google.com/store/apps/details?id=" : "http://www.amazon.com/gp/mas/dl/android?p=") +getPackageName())));
} catch (ActivityNotFoundException e2) {
Toast.makeText(this, "You don't have any app that can open this link", Toast.LENGTH_SHORT).show();
}
}
}
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();
源