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)
.
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
ForceUpgrade
dynamically displays Play Store Location, goToPlayStore()
can be used for redirect to Play Store page:-
- Release Notes
- Rating
- Commenting
There are two ways you can use the library either one will work fine, depending on your implementation.
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();
}
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();
}
}
}
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.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.alkathirikhalid:forceupgrade:v1.01'
}
<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>
- Document download: https://github.com/alkathirikhalid/forceupgrade/releases/download/v1.01/docs.zip
- AAR download: https://github.com/alkathirikhalid/forceupgrade/releases/download/v1.01/forceupgrade.aar
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.