项目作者: p32929

项目描述 :
A simple, Lightweight App Updater Library for Android
高级语言: Java
项目地址: git://github.com/p32929/AndroidAppUpdater.git
创建时间: 2019-05-29T06:28:09Z
项目社区:https://github.com/p32929/AndroidAppUpdater

开源协议:MIT License

下载


AndroidAppUpdater

A simple, Lightweight App Updater Library for Android

Share

Sharing with your friends is just one click away from here

facebook
twitter
tumblr
pocket
pinterest
reddit
linkedin
whatsapp

Support

If you like my works and want to support me/my works, feel free to support or donate. My payment details can be found here: https://p32929.github.io/SendMoney2Me/

Installation

Add it in your root build.gradle at the end of repositories:

  1. allprojects {
  2. repositories {
  3. maven { url 'https://jitpack.io' }
  4. }
  5. }

Add the dependency

  1. dependencies {
  2. implementation 'com.github.p32929:AndroidAppUpdater:1.0.2'
  3. }

Basic Usage

Steps to follow:

  • Create new new AppUpdater(context, jsonUrl, listener)
  • Execute the task
  • Do something if update is available

Code example

In your Activity or Fragment, you can add the code below:

  1. new AppUpdater(this, "https://raw.githubusercontent.com/p32929/SomeHowTosAndTexts/master/Updater/updater.json", new UpdateListener() {
  2. @Override
  3. public void onJsonDataReceived(final UpdateModel updateModel, JSONObject jsonObject) {
  4. if (AppUpdater.getCurrentVersionCode(MainActivity.this) < updateModel.getVersionCode()) {
  5. new AlertDialog.Builder(MainActivity.this)
  6. .setTitle("Update available")
  7. .setCancelable(updateModel.isCancellable())
  8. .setPositiveButton("Update", new DialogInterface.OnClickListener() {
  9. @Override
  10. public void onClick(DialogInterface dialog, int which) {
  11. Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(updateModel.getUrl()));
  12. startActivity(browserIntent);
  13. finish();
  14. }
  15. })
  16. .show();
  17. }
  18. }
  19. @Override
  20. public void onError(String error) {
  21. // Do something
  22. }
  23. }).execute();

the JSON data should be like below:

  1. {
  2. "versionCode": 1, // Updated version code
  3. "cancellable": false, // If you want to force users to update the app
  4. "url": "http://tiny.cc/BuySellBD" // If you want users to update the app from an External URL or from the Google Play URL
  5. }

If you add more data in the JSON file, you can get them from the jsonObject variable.

Hope you will enjoy using the library :)
Thanks :)

License:

  1. MIT License
  2. Copyright (c) 2019 Fayaz Bin Salam
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.