"评价此应用" - 手机上的Google Play商店应用中的链接

Adr*_*eno 244 android android-intent google-play

我想在Android应用中添加"评价此应用"链接,以便在手机上打开用户Google Play商店应用中的应用列表.

  1. 我必须编写哪些代码才能在手机上的Google Play商店应用中创建market://or http://-link?
  2. 你把代码放在哪里?
  3. 有没有人有这样的示例实现?
  4. 您是否必须指定放置market://http://链接的屏幕,哪个最适合使用 - market://或者http://

mig*_*las 515

我使用以下代码从我的应用程序打开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())));
    }
Run Code Online (Sandbox Code Playgroud)

这将启动Play商店,您的应用页面已经打开.用户可以在那里评分.

  • 这个解决方案不计入Play市场的后台堆栈.按下后退按钮后,您将无法返回到您的应用程序.如果需要,请添加以下行:intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); (57认同)
  • Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET:这个常量在API级别21中已弃用.从API 21开始,这与FLAG_ACTIVITY_NEW_DOCUMENT相同,应该使用它来代替此. (20认同)
  • 在androidmanifest.xml中我放置此代码的位置?我还需要添加其他内容吗?这与用户按下的屏幕上的实际链接或按钮有何对应?谢谢 (2认同)
  • 如果从非 Activity java 类调用,您需要传递上下文,如 context.startActivity(goToMarket); (2认同)

Gyö*_*dek 41

这是一个工作和最新的代码:)

/*
* 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;
}
Run Code Online (Sandbox Code Playgroud)

将代码放入Activity您想要的代码中.
当用户单击按钮对应用程序进行评级时,只需调用该rateApp()功能即可.


Cab*_*zas 22

我总是使用这段代码:

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

  • 总是喜欢一个衬垫.:) (4认同)

iDe*_*ode 18

Kotlin 解决方案(Google 在 2020 年提供的应用内评论 API):

您现在可以开箱即用地使用 Google 提供的 In app review 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'
}
Run Code Online (Sandbox Code Playgroud)

创建一个方法并将此代码放入其中:

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.
    }
}
Run Code Online (Sandbox Code Playgroud)

来源

在此处输入图片说明

  • 如果您使用 Kotlin 依赖项,则不需要使用以下这个:`implementation 'com.google.android.play:core:1.8.0'` (2认同)

Hải*_*ong 17

这是您在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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


K_A*_*nas 9

您始终可以从PackageManager类调用getInstalledPackages()并检查以确保安装了市场类.您还可以使用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);
Run Code Online (Sandbox Code Playgroud)

如果列表至少有一个条目,那么市场就在那里.

您可以使用以下命令在应用程序页面上启动Android Market,它更加自动化:

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

如果您想在模拟器上测试它,您可能没有安装市场:请参阅以下链接以获取更多详细信息:

如何在Google Android模拟器中启用Android电子市场

在Android模拟器上安装Google Play


gtg*_*ray 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();
}
Run Code Online (Sandbox Code Playgroud)

  • @SagarBalyan,这是在Google Play市场应用程序中打开您的应用页面的特殊用户.如果您使用链接启动活动,那么android将在默认浏览器中打开您的应用页面,或者您可以选择要启动的浏览器应用 (2认同)

iDe*_*ode 7

Java解决方案(2020年Google推出的应用内评论API):

\n

您现在可以使用 Google 提供的开箱即用的应用内审核 API。

\n

首先,在您的文件中添加以下依赖项(完整设置可以在此处build.gradle(app)找到

\n
dependencies {\n    // This dependency is downloaded from the Google\xe2\x80\x99s Maven repository.\n    // So, make sure you also include that repository in your project\'s build.gradle file.\n    implementation \'com.google.android.play:core:1.8.0\'\n}\n
Run Code Online (Sandbox Code Playgroud)\n

将此方法添加到您的Activity

\n
void askRatings() {\n    ReviewManager manager = ReviewManagerFactory.create(this);\n    Task<ReviewInfo> request = manager.requestReviewFlow();\n    request.addOnCompleteListener(task -> {\n        if (task.isSuccessful()) {\n            // We can get the ReviewInfo object\n            ReviewInfo reviewInfo = task.getResult();\n            Task<Void> flow = manager.launchReviewFlow(this, reviewInfo);\n            flow.addOnCompleteListener(task2 -> {\n                // The flow has finished. The API does not indicate whether the user\n                // reviewed or not, or even whether the review dialog was shown. Thus, no\n                // matter the result, we continue our app flow.\n            });\n        } else {\n            // There was some problem, continue regardless of the result.\n        }\n    });\n}\n
Run Code Online (Sandbox Code Playgroud)\n

然后你可以简单地使用它来调用它

\n
askRatings();\n
Run Code Online (Sandbox Code Playgroud)\n

来源

\n

在此输入图像描述

\n


Khe*_*raj 7

从现在起,您可以使用Google 的应用内评级功能

这是 Kotlin/Java 集成官方指南

Google Play 应用内评论 API 可让您提示用户提交 Play 商店评分和评论,而无需离开您的应用或游戏。

一般来说,应用内审核流程(见图 1)可以在应用的整个用户旅程中随时触发。在此流程中,用户可以使用 1 到 5 星系统对您的应用程序进行评分,并添加可选评论。提交后,评论将发送到 Play 商店并最终显示。

SC


Kes*_*era 6

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())));
                }
            }
        });
Run Code Online (Sandbox Code Playgroud)


kuz*_*zdu 6

一个 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)
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 5

关于基于 getPackageName() 策略实现的所有答案,有一点是,如果您使用相同的代码库构建具有不同应用程序 id 的多个应用程序(例如,白标产品)。