简体   繁体   English

如果有新的应用版本可用,如何触发更新 ( FROM GITHUB )

[英]How to trigger update if the new app version is available ( FROM GITHUB )

In my application I want to create a feature which would on startup check if there is a new version of the application available.在我的应用程序中,我想创建一个功能,它会在启动时检查是否有新版本的应用程序可用。 If yes then show an alert with "Yes/No" options.如果是,则显示带有“是/否”选项的警报。

I already tried to use a library from this guy GitHub .我已经尝试使用这个家伙GitHub的库。 I tried to do it via pure GitHUB and via UpdateFrom.XML but nothing seems to work.我试图通过纯 GitHUB 和 UpdateFrom.XML 来做到这一点,但似乎没有任何效果。

I have something like this我有这样的东西

override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
        val toolbar: Toolbar = findViewById(R.id.toolbar)
        setSupportActionBar(toolbar)

        val policy: StrictMode.ThreadPolicy = StrictMode.ThreadPolicy.Builder().permitAll().build()
        StrictMode.setThreadPolicy(policy)


        val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
        val navView: NavigationView = findViewById(R.id.nav_view)
        val toggle = ActionBarDrawerToggle(
            this,
            drawerLayout,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close
        )
        drawerLayout.addDrawerListener(toggle)
        toggle.syncState()

        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)

        navView.setNavigationItemSelectedListener(this)
        var updater = AppUpdater(this)
            .setUpdateFrom(UpdateFrom.XML)
            .setDisplay(Display.DIALOG)
            .setTitleOnUpdateAvailable("Nová verzia dostupná")
            .setContentOnUpdateAvailable("Stiahnite si prosím novú verziu aplikácie")
            .setTitleOnUpdateNotAvailable("Nová verzia nie je dostupná")
            .setContentOnUpdateNotAvailable("Nová verzia aplikácie  nie je dostupná. Skúste neskôr")
            .setButtonUpdate("Stiahnúť")
            .setButtonDismiss("Neskôr")
            .setIcon(R.drawable.ic_system_update_white_24dp)
            .setCancelable(false)
            .setUpdateXML("https://github.com/MyAccount/MyApp/tree/master/app/src/main/res/xml/provider_paths.xml")

        updater.start()
}

As I said above.正如我上面所说。 I want to check a version of the app and if there is a newer version than download it and update a current version of the app.我想检查应用程序的版本,以及是否有比下载更新的版本并更新应用程序的当前版本。

To quickly answer your question - yes , you can store your releases in GitHub releases page, then hard-code the link to that page in your app, and using a clever parser (or GitHub API) you would be able to get links for apps to download.为了快速回答您的问题 -的,您可以将您的版本存储在 GitHub 版本页面中,然后在您的应用程序中硬编码指向该页面的链接,并使用聪明的解析器(或 GitHub API)您将能够获取应用程序的链接去下载。 So doing it manually is possible for sure.因此,可以肯定地手动进行。

But instead, I'll try to convince you not to do this , and there are multiple reasons I can think of.但相反,我会尝试说服你不要这样做,我能想到的原因有很多。 You should always use a distribution channel like Google Play or other alternatives .您应该始终使用 Google Play 等分销渠道或其他替代渠道。

  • You get network stability, 99.9% availability and full CDN access for free, as GitHub or other storage options might be blocked in the region where the app is being used.您可以免费获得网络稳定性、99.9% 的可用性和完整的 CDN 访问权限,因为 GitHub 或其他存储选项可能在使用该应用程序的区域被阻止。 If you choose the right distributor, you'll never have this problem如果您选择合适的经销商,您将永远不会遇到这个问题
  • Your custom logic for checking whether there's an update or not.. it might have a bug: 1.0.2-beta vs. 1.0.2, which one is newer?您用于检查是否有更新的自定义逻辑..它可能有一个错误:1.0.2-beta 与 1.0.2,哪个更新? Sorting algorithms you get by default will most likely give you the beta (which is wrong).您默认获得的排序算法很可能会给您提供测试版(这是错误的)。 In this case you also have to be very careful to name your releases properly, and it's a lot of work to make sure you don't make a mistake here在这种情况下,您还必须非常小心地正确命名您的版本,并且要确保您不会在这里犯错需要做很多工作
  • Internal testing, automatic background updates, beta testing.. all of this is nearly impossible without a distributor内部测试、自动后台更新、beta 测试……如果没有分销商,这一切几乎是不可能的
  • Staged rollout, again, nearly impossible without a distributor再一次,分阶段推出,如果没有分销商,几乎是不可能的
  • Segmenting downloads, ie making the update available only to a certain group of people, impossible without support for this on the backend side that's hosting your app.分段下载,即只对特定人群提供更新,如果没有托管应用程序的后端对此提供支持,这是不可能的。 If you start implementing this feature yourself (on the backend), you'd be collecting user data and your backend would need to comply with GDPR or similar privacy law如果您自己(在后端)开始实施此功能,您将收集用户数据,并且您的后端需要遵守 GDPR 或类似的隐私法
  • Any download metric you might need in the future, once again, nearly impossible without a distributor再一次,您将来可能需要的任何下载指标,如果没有分销商,几乎是不可能的
  • In case you decide to switch to a distributor in the future, some users might have to uninstall the app and reinstall it to start getting automatic updates (this is bad UX)如果您决定将来切换到分销商,一些用户可能必须卸载该应用程序并重新安装它才能开始获取自动更新(这是糟糕的用户体验)
  • In terms of UX, you would be blocking the user from proceeding to the app until they download the new version (even if it's not blocking, it's one more step) - how many users would really click on 'update' if given a choice?在用户体验方面,您将阻止用户继续使用该应用程序,直到他们下载新版本(即使它没有阻止,这也是一个步骤) - 如果有选择,有多少用户会真正点击“更新”? Probably not many, so you wouldn't get too much from it anyway可能不多,所以无论如何你也不会从中得到太多
  • Downloading large items from a network location will require user confirmation, especially on a metered network... then you also need to check if they're on mobile data or WiFi (and is WiFi metered or not), so again - lot's of work.从网络位置下载大型项目需要用户确认,尤其是在计量网络上......然后您还需要检查它们是否在移动数据或 WiFi 上(并且是否 WiFi 计量),所以再次 - 很多工作. If connection breaks, you need to restart the download, and so on如果连接中断,则需要重新开始下载,依此类推
  • If you want to distribute your app only internally or only to a specific group of users (not keep it public), this is easy to do with most stores (for example in Google Play it's a couple of clicks)如果您只想在内部或仅向特定用户组分发您的应用程序(不公开),大多数商店都很容易做到这一点(例如在 Google Play 中,只需点击几下)
  • If you just want to force an update because of some protocol or backend/API change... again, not something you should fix on client side.如果您只是因为某些协议或后端/API 更改而只想强制更新......再次,您不应该在客户端修复。 Your backend needs be backwards-compatible forever as one of the basic requirements when there are mobile clients involved当涉及移动客户端时,您的后端需要永远向后兼容,这是基本要求之一

So yeah, lots of reasons not to do it yourself.所以,是的,有很多理由不自己做。 This is just from the top of my head (and not knowing reasons behind your question), but there are probably many more points to add.这只是我的想法(不知道你的问题背后的原因),但可能还有很多要补充的点。

And sure, there's probably an extremely narrow use-case when you'd really want to force updates manually, but in any case I'd recommend you to think about the consequences of going along this path.当然,当您真的想手动强制更新时,可能有一个非常狭窄的用例,但无论如何我建议您考虑走这条路的后果。

Update : Google will be releasing (has released?) a library that would allow you to check for updates, but even then you'd need to think about forcing updates in advance - at least one version ahead.更新:谷歌将发布(已经发布?)一个库,可以让你检查更新,但即便如此,你也需要提前考虑强制更新——至少提前一个版本。 Note also that Google services are not up-to-date on every device, and they're not available in many regions, so this is not 100% reliable either.另请注意,Google 服务并非在每台设备上都是最新的,并且它们在许多地区都不可用,因此这也不是 100% 可靠的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何警告用户新版本可用? - How to warn users that new version is available? GWT:当新版本可用时,如何强制客户端重新下载整个应用程序? - GWT: How to force client to re-download entire app when new version available? 当api 24和api 25中提供新版本时,Android以编程方式更新应用程序 - Android programmatically update application when a new version is available in api 24 and api 25 我是一名新的应用程序开发人员,我不确定如何将 github 中的项目插入到我的 android studio 应用程序中 - I am a new app developer and I am unsure on how to insert a project from github into my android studio app 如何从GitHub远程运行Android应用程序? - How to run Android app remotely from GitHub? 检查新版本(更新检查) - Checking for a New Version (Update Check) 如何从应用程序更新小部件? - How to update widget from app? 如何从 Java 应用程序触发 Linux 上的控制台应用程序 - How to trigger console app on Linux from Java app 当我使用数据库文件发布新版本的应用程序时,是否可以更新本地存储数据库中的特定表 - Is it possible to update specific table in locally stored database when I release a new version of the app by using database file 如何将 BoomMenu 库从 GitHub 添加到我的应用程序? - How can I add BoomMenu library from GitHub to my app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM