Saturday, 15 December 2018

Auto check for update function for android app | android studio

If you are having an app on Google Play Store and you want that whenever you update the app on playstore and when the user opens the older version of app he/she will get a dialog that there is an Update available .
Each time the user will open the app he/she will get the same dialog until he/she updates the app.


This will inform the user as a notice that there is an update.

Users will have the latest version of app.
Automatically checks for update in the background.
There is also an option for mannual check and automatic check.

How to use:

I have already create a class( to achieve this feature that will handle it automatically.
 package com.programmingdesire;  
 import android.content.DialogInterface;  
 import android.content.Intent;  
 import android.os.AsyncTask;  
 import android.widget.Toast;  
 import org.jsoup.Jsoup;  
 public class AppUpdateChecker {  
   private Activity activity;  
   public AppUpdateChecker(Activity activity) {  
     this.activity = activity;  
   //current version of app installed in the device  
   private String getCurrentVersion(){  
     PackageManager pm = activity.getPackageManager();  
     PackageInfo pInfo = null;  
     try {  
       pInfo = pm.getPackageInfo(activity.getPackageName(),0);  
     } catch (PackageManager.NameNotFoundException e1) {  
     return pInfo.versionName;  
   private class GetLatestVersion extends AsyncTask<String, String, String> {  
     private String latestVersion;  
     private ProgressDialog progressDialog;  
     private boolean manualCheck;  
     GetLatestVersion(boolean manualCheck) {  
       this.manualCheck = manualCheck;  
     protected void onPostExecute(String s) {  
       if (manualCheck)  
         if (progressDialog!=null)  
           if (progressDialog.isShowing())  
       String currentVersion = getCurrentVersion();  
       //If the versions are not the same  
         final AlertDialog.Builder builder = new AlertDialog.Builder(activity);  
         builder.setTitle("An Update is Available");  
         builder.setMessage("Its better to update now");  
         builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {  
           public void onClick(DialogInterface dialog, int which) {  
             //Click button action  
             activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+activity.getPackageName())));  
         builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {  
           public void onClick(DialogInterface dialog, int which) {  
             //Cancel button action  
         builder.setCancelable(false);  ;  
       }else {  
         if (manualCheck) {  
           Toast.makeText(activity, "No Update Available", Toast.LENGTH_SHORT).show();  
     protected void onPreExecute() {  
       if (manualCheck) {  
         progressDialog=new ProgressDialog(activity);  
         progressDialog.setMessage("Checking For Update.....");  
         progressDialog.setCancelable(false);  ;  
     protected String doInBackground(String... params) {  
       try {  
         //It retrieves the latest version by scraping the content of current version from play store at runtime  
         latestVersion = Jsoup.connect("" + activity.getPackageName() + "&hl=it")  
             .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/")  
             .select(".hAyfc .htlgb")  
         return latestVersion;  
       } catch (Exception e) {  
         return latestVersion;  
   public void checkForUpdate(boolean manualCheck)  
     new GetLatestVersion(manualCheck).execute();  

Add a library to your build.gradle(App level) file.

   implementation 'org.jsoup:jsoup:1.10.2'  

The last step is to copy that class and then write two lines of code.

 AppUpdateChecker appUpdateChecker=new AppUpdateChecker(this);  //pass the activity in constructure
 appUpdateChecker.checkForUpdate(false); //mannual check false here

Lets understand what is manual check

If manual check is true then
Manual check will be on a button click this will show the dialog as "Checking for update"

If manual  check is false then
Checking for update will be performed in the background and finally a dialog will be visible if there is any update.

If user will click on update it will open your app in playstore to update your app.

Thats all.

Thanks for visiting, I will come with new code snippet.
Happy Coding.......

Save Your Friends Status - WhatsApp Status Saver App

Love your friend's status ? Hesitate to ask? you are on the right page.

Its been easy to grab the whatsapp status of your whatsapp contacts.

So here are the steps to save or share the status (Image or Video) of whatsApp.

1. Install  WhatsApp Status Saver App by in your phone.

2. Open whatsApp and watch some status.

3.Come back to Status Saver and you will find the status there to download and share.

Directly open whatsapp from status saver . 

You can save status to your internal storage. 

You can directly share the status to whatsApp or any other social medial very easily by clicking on the share button. 

Now Enjoy the life with pride.

WhatsApp will give Rs 1.8 crores to new Indian startups, Here is all you need to know

The "Startup India WhatsApp Grand Challenge" has been appraise growth in the entrepreneurial sector. Total prize money of Rs 1.8...