Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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

class 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()
}
}
```