Adr*_*eno 244 android android-intent google-play
我想在Android应用中添加"评价此应用"链接,以便在手机上打开用户Google Play商店应用中的应用列表.
market://or http://-link?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商店,您的应用页面已经打开.用户可以在那里评分.
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)
iDe*_*ode 18
您现在可以开箱即用地使用 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)
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)
您始终可以从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电子市场
我使用这种方法让用户评价我的应用:
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)
您现在可以使用 Google 提供的开箱即用的应用内审核 API。
\n首先,在您的文件中添加以下依赖项(完整设置可以在此处build.gradle(app)找到)
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}\nRun Code Online (Sandbox Code Playgroud)\n将此方法添加到您的Activity:
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}\nRun Code Online (Sandbox Code Playgroud)\n然后你可以简单地使用它来调用它
\naskRatings();\nRun Code Online (Sandbox Code Playgroud)\n\n\n
从现在起,您可以使用Google 的应用内评级功能。
Google Play 应用内评论 API 可让您提示用户提交 Play 商店评分和评论,而无需离开您的应用或游戏。
一般来说,应用内审核流程(见图 1)可以在应用的整个用户旅程中随时触发。在此流程中,用户可以使用 1 到 5 星系统对您的应用程序进行评分,并添加可选评论。提交后,评论将发送到 Play 商店并最终显示。
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)
一个 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)
| 归档时间: |
|
| 查看次数: |
148833 次 |
| 最近记录: |