如何让用户从应用程序内部检查最新的应用程序版本?
我想在应用程序中添加一个“检查更新”按钮,以便当有人单击它时,它将显示一个 toast 消息/进度对话框以检查应用程序的版本。
如果发现新版本,应用程序将自动将其下载到手机并让用户手动安装更新的应用程序。
或者任何其他方法都可以,只要它可以检查最新版本并通知用户更新即可。
更新:现在,您可以使用 https 在应用内执行此操作://developer.android.com/guide/playcore/in-app-updates
I want to add a "Check for update" button in apps so that when someone clicks it, it will display a toast message / progress dialog for checking the app's version.
If new version is found the apps will auto download it to the phone and let user to manually install the updated apps.
Or any others method will do as long as it can check for latest version and notify the user to update.
Update: Now you can do this inside your app using https://developer.android.com/guide/playcore/in-app-updates
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
您可以使用此 Android 库: https://github.com/danielemaddaluno/Android-Update-Checker 。它的目的是提供一个可重用的工具来异步检查应用程序商店中是否存在任何较新发布的更新。
它是基于使用Jsoup(http://jsoup.org/)来测试新更新是否真的存在解析 Google Play 商店上的应用程序页面:
并且作为以下“值”函数(如果值在 0-99 之间,则有效):
如果您只想验证版本之间的不匹配,则可以更改:
值(curVersion)< value(newVersion)
与value(curVersion) != value(newVersion)
You can use this Android Library: https://github.com/danielemaddaluno/Android-Update-Checker. It aims to provide a reusable instrument to check asynchronously if exists any newer released update of your app on the Store.
It is based on the use of Jsoup (http://jsoup.org/) to test if a new update really exists parsing the app page on the Google Play Store:
And as "value" function the following (works if values are beetween 0-99):
If you want only to verify a mismatch beetween versions, you can change:
value(curVersion) < value(newVersion)
withvalue(curVersion) != value(newVersion)
如果它是市场上的应用程序,则在应用程序启动时,触发一个 Intent 以打开市场应用程序,希望这会导致它检查更新。
否则实施和更新检查器是相当容易的。这是我的代码(大致):
当然,您应该重写此代码以在后台线程上执行请求,但您明白了。
If it is an application on the Market, then on app start-up, fire an Intent to open up the Market app hopefully which will cause it to check for updates.
Otherwise implementing and update checker is fairly easy. Here is my code (roughly) for it:
Of course you should rewrite this to do the request on a background thread but you get the idea.
谷歌两个月前更新了 Play 商店。
这是现在对我有用的解决方案..
并且不要忘记添加 JSoup 库
和 Oncreate()
就是这样..
感谢此链接
Google updated play store two months before.
This is the solution working right now for me..
and don't forget to add JSoup library
and on Oncreate()
that's it..
Thanks to this link
将
compile 'org.jsoup:jsoup:1.10.2'
添加到 APP LEVEL build.gradle&
中的依赖项只需添加以下代码即可开始。
add
compile 'org.jsoup:jsoup:1.10.2'
to dependencies in APP LEVEL build.gradle&
Just add below code and you are good to go.
导航到您的播放页面:
使用标准 HTTP GET。
现在,以下 jQuery 会为您找到重要信息:
当前版本
新
功能既然您可以手动提取这些信息,只需在您的应用程序中创建一个方法来为您执行此操作。
使用 HtmlCleaner
Navigate to your play page:
Using a standard HTTP GET.
Now the following jQuery finds important info for you:
Current Version
What's new
Now that you can extract these information manually, simply make a method in your app that executes this for you.
Uses HtmlCleaner
没有用于此的 API,并且您无法自动安装它,您只需将它们重定向到其市场页面,以便他们可以升级。您可以将最新版本保存在 Web 服务器上的文件中,并让应用程序检查它。以下是此方法的一种实现:
http://code.google。 com/p/openintents/source/browse/#svn%2Ftrunk%2FUpdateCheckerApp
There is no API for this, and you can't auto install it, you can just redirect them to it's Market page so they can upgrade. You can have your latest version in a file on a Web server, and have the app check it. Here's one implementation of this:
http://code.google.com/p/openintents/source/browse/#svn%2Ftrunk%2FUpdateCheckerApp
我确实使用了应用内更新。仅适用于运行 Android 5.0(API 级别 21)或更高版本的设备,
I did using in-app updates. This will only with devices running Android 5.0 (API level 21) or higher,
以下是查找当前和最新可用版本的方法:
Here's how to find the current and latest available versions:
您应该首先查看市场上的应用程序版本,并将其与设备上的应用程序版本进行比较。如果它们不同,则可能有可用更新。在这篇文章中,我写下了获取当前市场版本和设备上当前版本的代码,并将它们放在一起进行比较。我还展示了如何显示更新对话框并将用户重定向到更新页面。请访问此链接:https://stackoverflow.com/a/33925032/5475941
You should first check the app version on the market and compare it with the version of the app on the device. If they are different, it may be an update available. In this post I wrote down the code for getting the current version of market and current version on the device and compare them together. I also showed how to show the update dialog and redirect the user to the update page. Please visit this link: https://stackoverflow.com/a/33925032/5475941
我知道OP很旧,当时 in-app-update 不可用。
但从 API 21 开始,您可以使用应用内更新检查。
您可能需要留意一些写得很好的要点 此处:
I know the OP was very old, at that time in-app-update was not available.
But from API 21, you can use in-app-update checking.
You may need to keep your eyes on some points which are nicely written up here:
使用 jsoup HTML 解析器库 @ https://jsoup.org/
您可以简单地为此创建一个方法;
Using jsoup HTML parser library @ https://jsoup.org/
You can simply create a method for that;
我们可以通过添加这些代码来检查更新:
首先我们需要添加依赖项:
其次,我们需要创建 Java 文件:
第三,我们需要在要显示更新的主类中添加此类:
I希望对你有帮助
We can check Update by Add these Code:
First we need to add dependencies :
Second we need to create Java File:
Third We need to add this class in your main class where you want to show the update:
I hope it will help you