Siren


Source link: https://github.com/eggheadgames/Siren

Siren for Android

Notify users when a new version of your Android app is available, and prompt them with the Play Store link.

This is a port of the iOS library of the same name: https://github.com/ArtSabintsev/Siren

About

Siren checks a user's currently installed version of your Android app against the latest version information stored in a JSON file on a server URL you provide. ( Unfortunately, the Google public API for version checking requires a token, and due to logistics and rate limiting, it's not feasible to use the API from an Android app).

If a new version is available, an alert can be presented to the user informing them of the newer version, and giving them the option to update the application. Alternatively, Siren can notify your app programmatically, enabling you to inform the user through alternative means, such as a custom interface.

  • Siren is built to work with semantic version numbering to provide a range of update suggestions for your customers
  • Siren is a Java language port of a Siren, an iOS Swift library that achieves the same functionality
  • Siren is actively maintained by Egghead Games for their cross-platform mobile/tablet apps ( great mind puzzles with no ads!)

Features

  • Gradle support (using JitPack)
  • Localized for 20+ languages (See Localization Section)
  • Three types of alerts (see Screenshots & Alert Types)
  • Optional override methods (see Optional Override section)
  • Accompanying sample Android app

Similar Android libraries

Choose what works best for your scenario. We chose not to "screenscrape" the Google Play Listing. We've kept the prompt & update scenarios simple. We kept close to the iOS Siren library to keep our iOS & Android apps similar. Other Android solutions: AppUpdater (the most comprehensive and feature rich library, including support for checks at Amazon and FDroid), Gandalf (also has a "companion" iOS solution), Update Checker, Fit (callback framework, no UI),

Screenshots & Alert Types

  • The left picture forces the user to update the app.
  • The center picture gives the user the option to update the app.
  • The right picture gives the user the option to skip the current update.
  • These options are controlled by the SirenAlertType enum.

Setup

A minimal usage is to add the following to the onCreate of your main activity. This will check at most once a day for a new version and give the user the option to choose "Update" or "Next time".

private static final String SIREN_JSON_URL = "https://example.com/com.mycompany.myapp/version.json";  Siren siren = Siren.getInstance(getApplicationContext());
 siren.checkVersion(this, SirenVersionCheckType.DAILY, SIREN_JSON_URL);

Installation Instructions

Add the JitPack.io repository to your root build.gradle:

allprojects {

  repositories {

maven {
 url "https://jitpack.io" 
}

  
}
 
}

Add a dependency to your application related build.gradle

dependencies {

  compile 'com.github.eggheadgames:Siren:1.4.+' 
}

Host a Json document with a public access that will describe your application package name and current application version.

{
 "com.example.app": {
 "minVersionName": "1.12.2" 
}
 
}

OR

{
 "com.example.app": {
 "minVersionCode": 7 
}
 
}

Options

The SirenVersionCheckType controls how often the server is checked for a new version, and hence how often the user will be prompted. You can set it to IMMEDIATELY, DAILY or WEEKLY.

You can also define the dialog appearance and behaviour by setting SirenAlertType to react according to your version increment per Semantic Versioning. The default is SirenAlertType.OPTION. This generates a 2 button "Next Time" or "Update" alert. Other values are FORCE, SKIP and NONE. NONE will not display an alert, but will call your listener with appropriate text to display. See Example below.

You can combine these options to have different behaviour for different version changes. For example, you might will force a user to upgrade for a major version change (e.g. 1.x.x to 2.x.x), give them a "Next time" option for a minor version change (e.g. 1.2.x to 1.3.x) and add a 3rd "Skip this version" option for a 3rd or 4th level change (e.g. 1.2.5 to 1.2.6).

As well as the levels: Major, Minor, Patch and Revision, you can also set messages based on the versionCode of your app by using a minVersionCode field instead of minVersionName.

The following code shows how you can display "stricter" dialogs based on the version severity, with no dialog displayed for a versionCode change:


  Siren siren = Siren.getInstance(getApplicationContext());

siren.setMajorUpdateAlertType(SirenAlertType.FORCE);

siren.setMinorUpdateAlertType(SirenAlertType.OPTION);

siren.setPatchUpdateAlertType(SirenAlertType.SKIP);

siren.setRevisionUpdateAlertType(SirenAlertType.NONE);

siren.checkVersion(this, SirenVersionCheckType.IMMEDIATELY, SIREN_JSON_DOCUMENT_URL);

If you'd like to just use versionCode for changes, you could check every time and force an update using code like this:


  Siren siren = Siren.getInstance(getApplicationContext());

siren.setVersionCodeUpdateAlertType(SirenAlertType.FORCE);

siren.checkVersion(this, SirenVersionCheckType.IMMEDIATELY, SIREN_JSON_DOCUMENT_URL);

Example

Some developers may want to display a less obtrusive custom interface, like a banner or small icon. You may also wish to control which level of update to force a user to update vs deferring to later.

You can find a fully functional sample project at https://github.com/eggheadgames/SirenSample.

Here is a code sample that shows how to handle all the alerts yourself:

 private void checkCurrentAppVersion() {

Siren siren = Siren.getInstance(getApplicationContext());

siren.setSirenListener(sirenListener);

siren.setMajorUpdateAlertType(SirenAlertType.NONE);

siren.setMinorUpdateAlertType(SirenAlertType.NONE);

siren.setPatchUpdateAlertType(SirenAlertType.NONE);

siren.setRevisionUpdateAlertType(SirenAlertType.NONE);

siren.setVersionCodeUpdateAlertType(SirenAlertType.NONE);

siren.checkVersion(this, SirenVersionCheckType.IMMEDIATELY, SIREN_JSON_DOCUMENT_URL);

  
}

ISirenListener sirenListener = new ISirenListener() {

@Override

public void onShowUpdateDialog() {

 Log.d(TAG, "onShowUpdateDialog");

}

 @Override

public void onLaunchGooglePlay() {

 Log.d(TAG, "onLaunchGooglePlay");

}

 @Override

public void onSkipVersion() {

 Log.d(TAG, "onSkipVersion");

}

 @Override

public void onCancel() {

 Log.d(TAG, "onCancel");

}

 @Override

public void onDetectNewVersionWithoutAlert(String message) {

 Log.d(TAG, "onDetectNewVersionWithoutAlert: " + message);

}

 @Override

public void onError(Exception e) {

 Log.d(TAG, "onError");

 e.printStackTrace();

}

  
}
;

Localization

Siren is localized for Arabic, Armenian, Basque, Chinese (Simplified), Chinese (Traditional), Danish, Dutch, English, Estonian, French, German, Hebrew, Hungarian, Italian, Japanese, Korean, Latvian, Lithuanian, Malay, Polish, Portuguese (Brazil), Portuguese (Portugal), Russian, Slovenian, Swedish, Spanish, Thai, and Turkish.

You may want the update dialog to always appear in a certain language, ignoring Android's language setting. This is supported with the setLanguageLocalization method. For example, you can force a French update dialog by setting the locale as follows:

 Siren.setLanguageLocalization(SirenSupportedLocales.FR)

Testing Siren

Change the url in your app to point to a test location (e.g. http://myjson.com/ is a convenient test site). Create an appropriate file and run your app with the temporary url.

For example, if my app's current version is 2.1.0.0 and the applicationId is com.eggheadgames.sirensample, I could create a json file with contents:

{
"com.eggheadgames.sirensample":{
"minVersionName":"2.2.1.1"
}

}

Then, add code like the following in the onCreate() of my app's home page:

 private Siren siren = Siren.getInstance(getApplicationContext());

  siren.checkVersion(this, SirenVersionCheckType.IMMEDIATELY, "https://api.myjson.com/bins/198mf");

Running this should show an update dialog when I start the app. Of course using a value other than IMMEDIATELY may not bring an immediate prompt, unless your SharedPreferences are being deleted between attempts.

Resources

A beautiful Tinder like card deck & Captain Train like toolbar.

Frodo is an android library inspired by Hugo, mainly used for logging RxJava Observables and Subscribers outputs on the logcat. It generates and weaves code based on annotations only on debug versions of the application where the plugin is applied, for instance, it is safe to persist any Frodo annotation in the codebase.

An android color picker with changeable color drawable for easy styling.

This custom listview basically shows a holder view when it's adapter is empty. For example, you may fetch list datas from network and refresh your adapter with coming data. If the data is empty, your listview shows a huge blank space. With this custom listview, you can show a holder view instead of blank space and your design looks prettier.

Android M was added to check permissions, but permissions checking is so dirty.

This project allows to check permissions easily.

The library distributes canvas animation over set of devices.

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