我想在Android应用程序中放置一个“评价此应用程序”的链接,以打开用户手机上的Google Play商店应用程序中的应用程序清单。
- 我需要编写什么代码才能创建
market://
或http://
链接并在手机上的Google Play商店应用程序中打开? - 您将代码放在哪里?
- 有人有这个的示例实现吗?
- 您是否必须指定
market://
或http://
链接将放置的屏幕,哪个最好使用-market://
还是http://
?
我想在Android应用程序中放置一个“评价此应用程序”的链接,以打开用户手机上的Google Play商店应用程序中的应用程序清单。
market://
或http://
链接并在手机上的Google Play商店应用程序中打开?market://
或http://
链接将放置的屏幕,哪个最好使用-market://
还是http://
?我使用以下代码从我的应用程序中打开 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();
}
这里有一份运作良好且最新的代码 :)
/*
* 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()
函数即可。
我经常使用这段代码:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=PackageName")));
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=PackageName }
- 我该怎么办? - Mina Daheshtry { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("bazaar://details?id=vow_note.maxsoft.com.vownote")); intent.setData(Uri.parse("myket://comment?id=vow_note.maxsoft.com.vownote")); startActivity(intent); }catch (ActivityNotFoundException e1) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("MARKET URL"))); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("MARKET URL"))); } catch (ActivityNotFoundException e2) {Toast.}
- Mina Dahesh现在,您可以直接使用由Google提供的应用内评论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.
}
}
implementation 'com.google.android.play:core:1.8.0'
- dansamosudov如果您在Google Play商店和Amazon应用商店都发布了您的应用程序,则需要考虑以下情况。我还处理用户(尤其是中国用户)没有安装应用商店和浏览器的情况。
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();
}
}
}
Intent
成为可行的类型,我应该使用什么命名空间? 我找到了Android.Content,但在Xamarin Forms中,我对Intent
感到困惑。 - s3c您可以从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);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=" + getPackageName()));
startActivity(i);
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();
}
market://details?id=
我的应用链接类似于 https:\\play.google.com\apps\details?id=
- Sagar Balyanfun 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)
}
}
Uri.parse("market://details?id=" + context.packageName)
和 catch 块中的第二个链接 Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName))
有什么不同吗?我认为这是多余的。 - Dr Mido现在您可以直接使用Google提供的应用内评论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'
}
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();
应用商店评分
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())));
}
}
});