android - 如何将用户导航到 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#
我错过了什么?
提前致谢。
解决方案
可能您只是以错误的方式设置包名称。为了更好地检测问题,请尝试在没有数据库数据的情况下直接运行它,如下所示:
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)));
}
推荐阅读
- java - 在 Java 中没有得到 ArithmeticException
- android - 如何覆盖flutter apk清单?
- ubuntu - 通过用户类分配 ISC-DHCP-Server IP 池
- kotlin - 使用 Kotlin 的扩展函数来抑制返回值
- javascript - 我可以调用多少个匿名函数
- r - R 将曲线线宽增加到 150%
- sql - 使用 sparksql 将 json 文件数据插入 sql 表
- ios - 执行代码以响应 iOS 通知
- python-3.x - Python 错误“ModuleNotFoundError:没有名为 libs.gpu.GpuWrapper 的模块”
- c# - C#/C++ 如何获取所有桌面(包括非活动桌面)的屏幕截图或渲染帧