alkathirikhalid / forceupgrade

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

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

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

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

License:Apache License 2.0


Languages

Language:Java 100.0%