[英]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 等分销渠道或其他替代渠道。
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.