ForceUpdate


Source link: https://github.com/skoumalcz/force-update

ForceUpdate

Force your users to update the app, or notify about non-critical updates.

This library is currently in concept phase. Feel free to star it, but do not try to use it :-)

Download

Download the latest JAR:

or include via Gradle:

compile 'net.skoumal.forceupdate:force-update:0.1.0'

Recommended usage

Only few lines of code are needed to notify and force your users to update your application in serious cases, such as a critical error or backend incompatibility with an old version of your app.

First, create a JSON file in this format and publish it:

 {

"min_allowed_version": "1.0.0",

"excluded_versions" : [ {
 "version" : "1.0.3" 
}
, {
 "version" : "2.0.1" 
}
]
  
}

Now add ForceUpdate initialization to your Application.onCreate():

 new ForceUpdate.Builder()

 // required - needs android.app.Application object

.application(this)

 // load all data from your json file

.masterVersionProvider(new JsonHttpMasterVersionProvider("http://your.domain/path/to/above.json"))

 // with exception for new version notifications

.recommendedVersionProvider(new CarretoGooglePlayVersionProvider())

 // we are done

.buildAndInit();

Now all your users will be:

  • forced to update all installations with versions below 1.0.0
  • forced to update installations with versions 1.0.3 and 2.0.1
  • notified about available update with every new version on Google Play

Version providers

You can load your version requirements from any place and any format. There is set of ready-to-use version providers, but you can also create your own if you need something special.

By default, every provider is polled once every 24 hours for its version.

 new ForceUpdate.Builder()

 // required - needs android.app.Application object

.application(this)

 // custom provider for minimal required version

.minAllowedVersionProvider(new MyCustomVersionProvider())

 // poll the min-allowed-version provider every 4 hours

.minAllowedVersionCheckMinInterval(4 * 3600)

 // custom provider for recommended version provider

.recommendedVersionProvider(new AnotherCustomVersionProvider())

 // poll the recommended-version provider every 6 hours

.recommendedVersionCheckMinInterval(6 * 3600)

 // custom provider for exluded version list

.excludedVersionProvider(new MyExcludedVersionListProvider())

 // poll the excluded-version provider every 8 hours

.excludedVersionCheckMinInterval(8 * 3600)

 // you can also load apk version your own way if needed

.currentVersionProvider(new ApkVersionProvider())

 .buildAndInit();

Sometimes you need to load more data from one physical source, like in the first example where we load min-allowed and excluded versions from one JSON file:

 {

"min_allowed_version": "1.0.0",

"excluded_versions" : [ {
 "version" : "1.0.3" 
}
, {
 "version" : "2.0.1" 
}
],

"recommended_version" : "3.0.3"
  
}

You can load all three versions from JSON file above

 new ForceUpdate.Builder()

 // required - needs android.app.Application object

.application(this)

 // one provider for all versions, can be overwritten by methods above

.masterVersionProvider(new JsonHttpMasterVersionProvider("http://your.domain/path/to/above.json"));

 .buildAndInit();

View customization

Simply define your own views for Force-Update Activity and/or for recommended-update Dialog:

 new ForceUpdate.Builder()

 // required - needs android.app.Application object

.application(this)

 // defaults to predefined activity

.forcedUpdateView(R.layout.force_update_activity)

 // defaults to predefined dialog

.recommendedUpdateView(R.layout.recommend_update_dialog)

 .buildAndInit();

Use your own activities:

 new ForceUpdate.Builder()

 // required - needs android.app.Application object

.application(this)

 // defaults to predefined activity

.forcedUpdateView(MyForceUpdateActivity.class)

 // defaults to predefined dialog

.recommendedUpdateView(MyRecommendedUpdateActivity.class)

 .buildAndInit();

Or provide completely custom implementation of UpdateView interface:

 new ForceUpdate.Builder()

 // required - needs android.app.Application object

.application(this)

 // defaults to predefined activity

.forcedUpdateView(new MyUpdateView())

 // defaults to predefined dialog

.recommendedUpdateView(new OtherUpdateView())

 .buildAndInit();

Usage

This library was designed with full customisability in mind. Whole library is based on three simple terms:

  • VersionProvider - provides version from a source, for example from your APK, Google Play, your server, or any other third party service. You can choose one of existing VersionProviders or create your own.

  • UpdateView - abstraction of the way how we notify user about new version available (recommended update) or about necessary update (forced update). Predefined Activities and dialogs are available as well.

  • CheckInterval - how often should we poll VersionProvider for new data. The under-the-hood strategy is to poll with every Activity.onResume() event if MinInterval is already reached.

Use the simple builder in your Application to init ForceUpdate:

 new ForceUpdate.Builder()

 // required - needs android.app.Application object

.application(this)

 // defaults to NULL - no force update view will ever appear

.minAllowedVersionProvider(new MyCustomVersionProvider())

 // defaults to 24 hours

.minAllowedVersionCheckMinInterval(4 * 3600)

 // defaults to version from http://carreto.pt/tools/android-store-version/?package=<your package>

.recommendedVersionProvider(new CarretoGooglePlayVersionProvider())

 // defaults to 24 hours

.recommendedVersionCheckMinInterval(6 * 3600)

 // defaults to NULL - no force update view will ever appear

.excludedVersionProvider(new MyExcludedVersionListProvider())

 // defaults to 24 hours

.excludedVersionCheckMinInterval(8 * 3600)

 // defaults to current apk version

.currentVersionProvider(new ApkVersionProvider())

 // defaults to predefined activity

.forcedUpdateView(new ForcedVersionActivityView())

 // defaults to predefined dialog

.recommendedUpdateView(new RecommendedVersionView())

 // one provider for all versions, overrides all VersionProviders

.masterVersionProvider(new MyMasterProvider());

 // alias for .build().init()

.buildAndInit();

Extras

ForceUpdate is able to detect crash during last version check and hangs main thread during next app start to avoid any other code execution and allow successful version check. If there is a new version available it automatically fires a notification.

Contact

Feel free to report any issues or for the library on contribute few pieces of code!

Follow us on Twitter! @skoumal_dev

License

Copyright 2016 SKOUMAL, s.r.o.  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

SimplePrefs is an Android library that helps working with SharedPreferences.

xpresso is a Java library inspired by Python. It allows a (near) line-into-line rewrite of a Python code into Java. It's also a great way to prototype your algorithms directly in Java.

Android ProgressBar that "bends" under its own weight.

This is an example project that uses Android Design Support Library.

PCollections serves as a persistent and immutable analogue of the Java Collections Framework. This includes efficient, thread-safe, generic, immutable, and persistent stacks, maps, vectors, sets, and bags, compatible with their Java Collections counterparts.

DeepLinkDispatch provides a declarative, annotation-based API to declare application deep links.

You can register an Activity to handle specific deep links by annotating it with @DeepLink and a URI. DeepLinkDispatch will parse the URI and dispatch the deep link to the appropriate Activity, along with any parameters specified in the URI.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes