首页 > 解决方案 > 如何将用户导航到 Google Play 以获取更新

问题描述

在我的数据库的帮助下,我手动编写了一种方法,该方法每天通知用户一次有更新并且用户尚未更新他们的应用程序。用户会看到一个警报对话框,如果单击“是”,他们将被定向到 Google Play 到该应用程序,但该应用程序不显示更新选项。即使有更新,它也只显示卸载和打开。在此页面中,如果您打开另一个应用程序等...返回同一页面,则可以看到更新选项。

这是警报对话框正按钮 OnClickListener 的代码:

                        builder.setPositiveButton(newVersion.getPositive(), (dialogInterface, i) -> {
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(newVersion.getUrl()));
                            intent.setPackage("com.android.vending");
                            startActivity(intent);
                        });
                        builder.show();

url 来自数据库,它是https://play.google.com/store/apps/details?id=#put_your_package_name_here#

我错过了什么?

提前致谢。

标签: android

解决方案


可能您只是以错误的方式设置包名称。为了更好地检测问题,请尝试在没有数据库数据的情况下直接运行它,如下所示:

Intent intent = new Intent(Intent.ACTION_VIEW, 
Uri.parse("https://play.google.com/store/apps/details?id=com.android.vending"));
startActivity(intent);

如果这不起作用,请尝试替换https://play.google.com/store/apps/details?id=market://details?id=执行以下操作:

Intent intent = new Intent. ACTION_VIEW,
Uri.parse("market://details?id=com.android.vending"));
startActivity(intent);

之后,您将知道哪个 Uri 适合您,然后您可以将其与您的逻辑一起使用。为了使其更加防弹,我建议您像这样使用两个 Uri:

final String packageName = "com.android.vending";
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details? id=" + packageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
}

推荐阅读