我想在Android应用中添加“评价此应用”链接,以便在手机上打开用户Google Play商店应用中的应用列表。
market://
或http://
- 链接?market://
或http://
链接的屏幕,哪个最适合使用?market://
或http://
?答案 0 :(得分:491)
我使用以下代码从我的应用程序打开Play商店:
Uri uri = Uri.parse("market://details?id=" + context.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=" + context.getPackageName())));
}
这将启动Play商店并打开您的应用页面。用户可以在那里评价。
答案 1 :(得分:36)
这是一个有效且最新的代码:)
/*
* Start with rating the app
* Determine if the Play Store is installed on the device
*
* */
public void rateApp()
{
try
{
Intent rateIntent = rateIntentForUrl("market://details");
startActivity(rateIntent);
}
catch (ActivityNotFoundException e)
{
Intent rateIntent = rateIntentForUrl("https://play.google.com/store/apps/details");
startActivity(rateIntent);
}
}
private Intent rateIntentForUrl(String url)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
if (Build.VERSION.SDK_INT >= 21)
{
flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
}
else
{
//noinspection deprecation
flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
}
intent.addFlags(flags);
return intent;
}
将代码放入您想要来的Activity
当用户点击按钮为应用评分时,只需调用rateApp()
功能。
答案 2 :(得分:21)
我总是使用这段代码:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=PackageName")));
答案 3 :(得分:16)
如果您在Google Play商店和Amazon Appstore中发布应用,则会如此。我还处理了用户(特别是在中国)没有app store和浏览器的情况。
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();
}
}
}
答案 4 :(得分:12)
您现在可以直接使用Google提供的应用内审核API。
首先,在您的build.gradle(app)
文件中,添加以下依赖项(可以在here中找到完整的设置)
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.
}
}
答案 5 :(得分:9)
您始终可以从getInstalledPackages()课程中拨打PackageManager并检查以确保已安装市场类。您还可以使用queryIntentActivities()来确保您构建的Intent能够被某些东西处理,即使它不是市场应用程序。这可能是最好的事情,因为它最灵活和最强大。
您可以通过
检查市场应用程序是否在那里Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=foo"));
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
如果列表至少有一个条目,那么市场就在那里。
您可以使用以下命令在应用页面上启动Android电子市场,它会更加自动化:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=" + getPackageName()));
startActivity(i);
如果您想在模拟器上测试它,您可能没有安装市场: 有关详细信息,请参阅以下链接:
How To Enable the Android Market in the Google Android Emulator
答案 6 :(得分:7)
我使用这种方法让用户评价我的应用:
public static void showRateDialog(final Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle("Rate application")
.setMessage("Please, rate the app at PlayMarket")
.setPositiveButton("RATE", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (context != null) {
String link = "market://details?id=";
try {
// play market available
context.getPackageManager()
.getPackageInfo("com.android.vending", 0);
// not available
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
// should use browser
link = "https://play.google.com/store/apps/details?id=";
}
// starts external action
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(link + context.getPackageName())));
}
}
})
.setNegativeButton("CANCEL", null);
builder.show();
}
答案 7 :(得分:3)
你可以使用它,它适用于我
public static void showRateDialogForRate(final Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle("Rate application")
.setMessage("Please, rate the app at PlayMarket")
.setPositiveButton("RATE", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (context != null) {
////////////////////////////////
Uri uri = Uri.parse("market://details?id=" + context.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_CLEAR_WHEN_TASK_RESET |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
context.startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
}
}
}
})
.setNegativeButton("CANCEL", null);
builder.show();
}
答案 8 :(得分:2)
另一种可能适合您的方法是Linkify。如果我有一个要求用户对应用评分的TextView,我可以在文本中链接几个单词以便突出显示,当用户触摸它们时,游戏商店会打开,准备好进行审核:
class playTransformFilter implements TransformFilter {
public String transformUrl(Matcher match, String url) {
return "market://details?id=com.qwertyasd.yourapp";
}
}
class playMatchFilter implements MatchFilter {
public boolean acceptMatch(CharSequence s, int start, int end) {
return true;
}
}
text1 = (TextView) findViewById(R.id.text1);
text1.setText("Please rate it.");
final Pattern playMatcher = Pattern.compile("rate it");
Linkify.addLinks(text1, playMatcher, "",
new playMatchFilter(), new playTransformFilter());
答案 9 :(得分:2)
从现在起您可以使用 In App Rating feature by Google。
Here is Kotlin/Java integration official guide
<块引用>Google Play In-App Review API 可让您提示用户提交 Play 商店评分和评论,而无需离开您的应用或游戏。
通常,应用内审核流程(见图 1)可以在 在您的应用程序的整个用户旅程中的任何时间。在流动过程中, 用户可以使用 1 到 5 星系统对您的应用进行评分,并且 添加可选注释。提交后,审核将发送至 Play 商店并最终显示出来。
答案 10 :(得分:2)
有关基于getPackageName()策略实现的所有答案的一点是使用BuildConfig.APPLICATION_ID可能更直接,如果您使用相同的代码库来构建具有不同应用ID的多个应用程序,则效果很好(对于例如,白色标签产品。)
答案 11 :(得分:2)
您现在可以直接使用Google提供的应用内审核API。
首先,在您的build.gradle(app)
文件中,添加以下依赖项(可以在here中找到完整的设置)
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();
答案 12 :(得分:1)
Play商店评分
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())));
}
}
});
答案 13 :(得分:1)
我使用以下方法,将this和this的答案组合在一起,而没有使用基于异常的编程,并且还支持API 21之前的意图标记。
private Intent getRateIntent()
{
String url = isMarketAppInstalled() ? "market://details" : "https://play.google.com/store/apps/details";
Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
int intentFlags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
intentFlags |= Build.VERSION.SDK_INT >= 21 ? Intent.FLAG_ACTIVITY_NEW_DOCUMENT : Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
rateIntent.addFlags(intentFlags);
return rateIntent;
}
private boolean isMarketAppInstalled()
{
Intent marketIntent = new Intent();
marketIntent.setAction(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse("market://search?q=foo"));
List<ResolveInfo> activitiesCanHandleIntent = getPackageManager().queryIntentActivities(marketIntent, 0);
return activitiesCanHandleIntent.size() > 0;
}
// use
startActivity(getRateIntent());
我还尝试了在其网站(2019年12月6日)上建议的 official Google way。据我了解,如果未安装Play Store应用,则无法解决这种情况:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
"https://play.google.com/store/apps/details?id=com.example.android"));
intent.setPackage("com.android.vending");
startActivity(intent);
答案 14 :(得分:1)
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)
}
}
答案 15 :(得分:1)
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.StringRes;
import android.widget.Toast;
public class PlayStoreLink {
public void checkForUpdate(Context context, int applicationId)
{
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.url_market_details)
+ applicationId)));
} catch (android.content.ActivityNotFoundException anfe) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.url_playstore_app)
+ applicationId)));
} catch (Exception e) {
Toast.makeText(context,
R.string.install_google_play_store,
Toast.LENGTH_SHORT).show();
}
}
}
public void moreApps(Context context, @StringRes int devName) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.url_market_search_app)
+ context.getString(devName))));
} catch (android.content.ActivityNotFoundException anfe) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.url_playstore_search_app)
+ context.getString(devName))));
} catch (Exception e) {
Toast.makeText(context,
R.string.install_google_play_store,
Toast.LENGTH_SHORT).show();
}
}
}
public void rateApp(Context context, int applicationId) {
try {
Uri uri = Uri.parse(context.getString(R.string.url_market_details)
+ applicationId);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH)
flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
else
flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
intent.addFlags(flags);
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
checkForUpdate(context, applicationId);
}
}
}
<string name="install_google_play_store" translatable="false">Please install google play store and then try again.</string>
<string name="url_market_details" translatable="false">market://details?id=</string>
<string name="url_playstore_app" translatable="false">https://play.google.com/store/apps/details?id=</string>
<string name="url_market_search_app" translatable="false">market://search?q=pub:</string>
<string name="url_playstore_search_app" translatable="false">http://play.google.com/store/search?q=pub:</string>
<string name="app_link" translatable="false">https://play.google.com/store/apps/details?id=</string>
devName是Play商店上开发者帐户的名称
答案 16 :(得分:1)
您应该使用这个简单的代码来评估您的活动中的应用。
try {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id="
+ getPackageName())));
}
答案 17 :(得分:0)
在活动类中声明一个方法。然后复制并粘贴下面的代码。
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())));
}
}
现在可以从代码的任何地方调用此方法。
按照下面的图片来自我的实际项目。
答案 18 :(得分:0)
这是我使用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)));
}
答案 19 :(得分:0)
In-App Review API 是一项期待已久的功能,Google 已于 2020 年 8 月推出,就像 Apple 在 2016 年为 iOS 应用推出的一样。
使用此 API,用户无需离开即可查看和评价应用程序。 Google 建议开发者不要一直强迫用户评分或评论,因为此 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)
答案 20 :(得分:0)
这个答案已经过去了很多时间,现在有一种方法可以将 GOOGLE PLAY 评论窗口附加到您的应用程序
https://developer.android.com/guide/playcore/in-app-review
// In your app’s build.gradle file:
...
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.10.0'
// For Kotlin users also add the Kotlin extensions library for Play Core:
implementation 'com.google.android.play:core-ktx:1.8.1'
...
}
然后当您想显示汇率时弹出
final ReviewManager manager = ReviewManagerFactory.create(context);
final 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(context, reviewInfo);
flow.addOnCompleteListener(task -> {
// 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, log or handle the error code.
@ReviewErrorCode int reviewErrorCode = ((TaskException) task.getException()).getErrorCode();
}
});
正如评论中所说,API 不会让您知道用户给出的评价
Google 对这个api 的使用也有严格的指导方针,你被允许显示窗口的频率是有限的,而且你也不能诱导用户给你一个好评。您可以在上面的链接中查看完整的文档和指南