Distributing In App Android Updates
Posted By : Karan Jeet Singh | 05-Aug-2019
Introduction
Daily, we come across tens and twenties of updates average, of our apps installed in our smartphones. These updates consist of different types ie. Bug fixes, new feature functionalities, crash fixes, old devices support backward compatibility and even promotional stuff. But how often do we update them? Even after being duly acknowledged about the fact that the new updates consist of what is needed to keep it alive.
Problem
This brings us to the problem area. Often developers face a ghastly problem of distributing app updates to their users without bugging them off frequently. Because that may lead to losing a user in the first place. It is a silent yet widely known notion that it's easy to lose a user rather than gaining and keeping its trust alive in the product that you built tirelessly. Let's face it, no mobile application is bug-free. There can always be circumstances either caused by the user or the app developers while introducing new features which can result in potential bugs or worse, fatal crashes. Which is why we need a subtle solution to ensure that users are informed about the updates in time.
Solution
Considering an average Android Smartphone user has at least 30 apps on its phone, a user gets rather reluctant to update all of them in just one go. And that entirely is up to user decision. But the best course of action that can be taken in that case is to provide it with In-App updates. Consider a scenario where the user opens a certain app and that shows a dialog asking it to update to the latest version of the app available on the Google Play Store. We must first check whether a new version is available on the Play Store or not. To check that we can use a fantastic time-saving 3rd Party Library that returns us the current version of the app called, Jsoup. Jsoup is a library that works with HTML and it provides the results to your requests using DOM, CSS, and jquery. Lets witness Jsoup in action.
try {
playStoreVersion = Jsoup.connect("https://play.google.com/store/apps/details?id="+context.getPackageName()+"&hl=en")
.timeout(10000)
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6)")
.referrer("http://www.google.com")
.get()
.select("div.hAyfc:nth-child(4) > span:nth-child(2) > div:nth-child(1) > span:nth-child(1)")
.first()
.ownText();
} catch (Exception e) {
Logger.LogError(VersionChecker.class.getSimpleName(), e.getMessage());
}
This code snippet will supply you the current version of your application that is available on the Google Play Store. Once, you get the result you can get it compared with your current version, if the version mismatches, display the dialog asking for an update. Notice the
context.getPackageName()
in the snippet. That will dynamically supply your package name as a request.
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Logger.LogError("Play Store Version", playStoreVersion);
checkForUpdate();
}
private void checkForUpdate(){
if(!BuildConfig.VERSION_NAME.equals(playStoreVersion)){
createAndShowUpdateDialog();
}
}
Weighing my two cents in, it's better to show the dialog the first screen after opening the application. Also, the fetching of the current version should be done using the AsyncTask as the main thread of the app should not be interrupted.
Conclusion
-
Jsoup is neither a paid or a complex service to understand
-
No potential support for the ensuing time, if services of Jsoup are discarded, your app may crash.
References
-
https://jsoup.org/
-
https://github.com/jhy/jsoup
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Karan Jeet Singh
Karan Jeet Singh's main area of interest is Android Development. He is familiar with Kotlin and C# in other programming languages. He is familiar with tools such as Android Studio, Visual Studio, NetBeans, Eclipse IDE.