A very simple way to let Android users update your app.
It is a wrapper of In-App Updates Google Play library with extra features to notify users for new updates and install them in an integrated way without leaving the app.
- Custom View which displays automatically when an update is available. Just add it in your main activity layout!
- UPDATE button included to launch the integrated update process of In-App Updates Google Play library
- Optional - Easy configuration of periodic Google Play updates checks. They run in background and displays a notification when an update is available.
- Add the dependency in your build.gradle file:
dependencies {
implementation 'com.triskelapps:simpleappupdate:{last_version}'
}
Note
- Check
{last_version}
in the Jitpack badge above - Add Jitpack repository in root gradle file if you don't have it already:
repositories {
...
maven { url 'https://jitpack.io' }
}
- Add the view to your main layout
<com.triskelapps.simpleappupdate.SimpleAppUpdateView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
With just these lines, the user will see a view if there is an update available of your app in Google Play. It includes an Update button and Close icon to hide the view for this session:
- If you want to customize that view, there are some properties to set the background and foreground colors (text color and icon tint) and the text style (font size, typography, etc.):
<com.triskelapps.simpleappupdate.SimpleAppUpdateView
android:id="@+id/simple_app_update_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:backgroundColor="@color/custom_background_color"
app:foregroundColor="@color/custom_foreground_color"
app:textStyle="@style/TextStyle" />
Tip
To check the view style without waiting the next Google Play update, just get the view by its id
and set visibility to VISIBLE programmatically
- If you need even more customization, you can implement your own view display process:
Kotlin
val simpleAppUpdate = SimpleAppUpdate(context)
simpleAppUpdate.setUpdateAvailableListener {
// show any view with a "launch update button" which calls this method:
// simpleAppUpdate.launchUpdate()
}
}
// Optionally use these callbacks:
simpleAppUpdate.setErrorListener { }
simpleAppUpdate.setFinishListener { }
// Finally, launch check update process:
simpleAppUpdate.checkUpdateAvailable()
Java
SimpleAppUpdate simpleAppUpdate = new SimpleAppUpdate(context);
simpleAppUpdate.setUpdateAvailableListener(() -> {
onUpdateAvailable(); // show view with button to launch update throught: simpleAppUpdate.launchUpdate();
return Unit.INSTANCE; // Needed for Java-Kotlin interoperability
});
simpleAppUpdate.checkUpdateAvailable();
The previous view inside the app is useful when user open the application. If you also want to notify the user in the background with a system notification, configure it this way:
val notificationStyle = NotificationStyle(R.mipmap.your_app_icon, R.color.custom_notif_color)
val workerConfig = WorkerConfig()
SimpleAppUpdate.schedulePeriodicChecks(context, BuildConfig.VERSION_CODE, notificationStyle, workerConfig)
Note
Inside checks scheduling, the library uses a Unique Work to ensure there is only one active work, so it is safe to call SimpleAppUpdate.schedulePeriodicChecks(...)
more than once, for example inside onCreate() method of Application class
- By default the checks periodicity is set to 8 hours (with 2 hours of flex interval). See documentation for more info.
If you want to set your own period, just add the parameters when building
WorkerConfig
:
val workerConfig = WorkerConfig(2, TimeUnit.HOURS, 30, TimeUnit.MINUTES)
- To cancel an active check update worker call:
simpleAppUpdate.cancelWork()
- To check the work status, you can access the WorkInfo data:
val workInfo = simpleAppUpdate.getWorkInfo()
For example you can check the enqueued state or the next schedule time
Debug the periodic check process is tricky as we would need to wait until the next process is triggered after the period. To make it easy, the library saves some logs, so you can leave the app for some time and then access the logs calling:
val logs: String = simpleAppUpdate.getLogs()
Note
The log has a maximum size of 100 entries