Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prongbang/inapp-update
In-app updates wrapper for Android.
https://github.com/prongbang/inapp-update
android in-app-update-android in-app-updates inapp-update
Last synced: 26 days ago
JSON representation
In-app updates wrapper for Android.
- Host: GitHub
- URL: https://github.com/prongbang/inapp-update
- Owner: prongbang
- License: mit
- Created: 2022-04-09T06:01:13.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-09T09:25:47.000Z (over 2 years ago)
- Last Synced: 2024-10-24T08:06:50.220Z (2 months ago)
- Topics: android, in-app-update-android, in-app-updates, inapp-update
- Language: Kotlin
- Homepage:
- Size: 106 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# inapp-update
[![](https://jitpack.io/v/prongbang/inapp-update.svg)](https://jitpack.io/#prongbang/inapp-update)
In-app updates wrapper for Android, Supported Java 11.
## Setup
- `build.gradle`
```groovy
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
}
```- `settings.gradle`
```groovy
dependencyResolutionManagement {
repositories {
maven { url 'https://jitpack.io' }
}
}
```- `app/build.gradle`
```groovy
implementation 'com.github.prongbang:inapp-update:1.0.1'
```## How to use
```kotlin
import com.google.android.play.core.install.model.AppUpdateType
import com.prongbang.appupdate.AppUpdateInstallerListener
import com.prongbang.appupdate.AppUpdateInstallerManager
import com.prongbang.appupdate.InAppUpdateInstallerManagerclass SplashActivity : AppCompatActivity() {
private val appUpdateInstallerManager: AppUpdateInstallerManager by lazy {
InAppUpdateInstallerManager(this)
}private val appUpdateInstallerListener by lazy {
object : AppUpdateInstallerListener() {
// On downloaded but not installed.
override fun onDownloadedButNotInstalled() = popupSnackBarForCompleteUpdate()// On failure
override fun onFailure(e: Exception) = navigateToMain()// On not update
override fun onNotUpdate() = navigateToMain()// On cancelled update
override fun onCancelled() = navigateToMain()
}
}override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
appUpdateInstallerManager.addAppUpdateListener(appUpdateInstallerListener)
appUpdateInstallerManager.startCheckUpdate()
}override fun onResume() {
super.onResume()
appUpdateInstallerManager.resumeCheckUpdate(AppUpdateType.FLEXIBLE)
// or
// appUpdateInstallerManager.resumeCheckUpdate(AppUpdateType.IMMEDIATE)
}override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
appUpdateInstallerManager.onActivityResult(requestCode, resultCode, data)
}private fun navigateToMain() {
startActivity(Intent(this, MainActivity::class.java))
finishAffinity()
}private fun popupSnackBarForCompleteUpdate() {
val snackBar = Snackbar.make(
findViewById(android.R.id.content),
"An update has just been downloaded.",
Snackbar.LENGTH_INDEFINITE
)
snackBar.setAction("RESTART") { appUpdateInstallerManager.completeUpdate() }
snackBar.setActionTextColor(ContextCompat.getColor(this, android.R.color.holo_red_dark))
snackBar.show()
}
}
```