GithubHelp home page GithubHelp logo

alkathirikhalid / forceupgrade Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 68 KB

An Android library to detect current installed app version and current published Play Store version.

Home Page: https://jitpack.io/#alkathirikhalid/forceupgrade/v1.01

License: Apache License 2.0

Java 100.00%
android-library aar broadcast android androidutils androidutility playstore playstorelink

forceupgrade's Introduction

Force Upgrade

An Android library to detect current installed app version and current published Play Store version and perform an automatic redirect to Play Store for an update if required for API 16 and above. This library has a fail safe mechanisim in the event no network is not available or timeout() occured in 10 Sec a 0 is set to playStoreVersion resulting isNewVersion() to False. Removing the need to check for network for the actual implimentation of ForceUpgrade library.

The only thing you need to pass from your App Activity is the Context of that Activity. It can be used in any Android project either using build script or adding aar file. Passing your Activity Context as such ForceUpgrade(this).

Usage

It is strogly advisable to to check isNewVersion() prior to invoking goToPlayStore() inorder to provide UI option or force redirect for upgrade, the former will improve UX while the latter improve your application logic to only redirect when there is an actual updated version in Play Store.

The code has been intentionally made to allow a redirect in the event the developer requires other implementaions of this library. Example: You may have an About App Screen and use ForceUpgrade to dynamically display the fields:-

  • Current Version: 1.5
  • Play Store Version: 1.7
  • Go To Play Store: Update
Oher than update, Since ForceUpgrade dynamically displays Play Store Location, goToPlayStore() can be used for redirect to Play Store page:-
  • Release Notes
  • Rating
  • Commenting

Usage Types

There are two ways you can use the library either one will work fine, depending on your implementation.

Delegation Pattern

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
		
	// Pass the Context and the Listener
        new ForceUpgrade(this).setOnTaskCompletionListener(new GetPlayStoreVersionTask() {
            @Override
            public void onTaskCompletion(Result result) {
		// Manipulate result as required when received.
                result.isNewVersion();
                result.getCurrentVersion();
                result.getPlayStoreVersion();
		// Check if an exception occurred resulting to 0 or there is no new version, prior redirect
                if (result.isNewVersion()) {
                   result.goToPlayStore();
                  }
            }
        }).execute();
}

Observer Pattern

public class MainActivity extends AppCompatActivity implements GetPlayStoreVersionTask{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
	// Pass the Context and the Listener
        ForceUpgrade forceUpgrade = new ForceUpgrade(this, this);
        forceUpgrade.execute();
    }

    @Override
    public void onTaskCompletion(Result result) {
		// Manipulate result as required when received
                result.isNewVersion();
                result.getCurrentVersion();
                result.getPlayStoreVersion();
		// Check if an exception occurred resulting to 0 or there is no new version, prior redirect
                if (result.isNewVersion()) {
                   result.goToPlayStore();
                  }
    }
}

Accesible and usable Methods

1. isNewVersion() Differentiates between the currentVersion installed in the device with playStoreVersion App Version in Play Store. true If the Play Store version is new, false If the Play Store version is old or connection failed.

2. getCurrentVersion() The current App Version installed.

3. getPlayStoreVersion() The current App Version in Play Store.

4. goToPlayStore() Broadcast App Link location for Interception by Device Google Play Store, inorder to redirect users to the current app in Play Store.If you have multiple application installed in the device that can handle the URI, all of them will receive the broadcast.

Installation

Gradle

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
dependencies {
	        compile 'com.github.alkathirikhalid:forceupgrade:v1.01'
	}

Maven

<repositories>
  	<repository>
  	    <id>jitpack.io</id>
  	    <url>https://jitpack.io</url>
  	</repository>
  </repositories>
<dependency>
      <groupId>com.github.alkathirikhalid</groupId>
      <artifactId>forceupgrade</artifactId>
      <version>v1.01</version>
  </dependency>

Further Resources

License

Copyright 2015 Al-Kathiri Khalid www.alkathirikhalid.com

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.

forceupgrade's People

Contributors

alkathirikhalid avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jamalla

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.