简体   繁体   中英

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 . I tried to do it via pure GitHUB and via UpdateFrom.XML but nothing seems to work.

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. 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 .

  • 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. 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? 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
  • 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
  • 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. 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)
  • 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM