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.

Sunday, 9 December 2018

How to insert images in C/ C++ using graphics(100% working)

Hello friends today we will learn how to insert images in  C++ language very easily using graphics.The things that are required for this work are listed here .....

1.Codeblocks compiler installed on your system:

Code::Blocks is a freeopen-source cross-platform IDE that supports multiple compilers including GCCClang and Visual C++. It is developed in C++ using wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and features are defined by the provided plugins. Currently, Code::Blocks is oriented towards CC++, and Fortran. It has a custom build systemand optional Make support.(by wikipedia).

2.Graphics libraries should set up with codeblocks:

When we install codeblocks then there is no library and header file of graphics are given by the developers with it, so we have to configure these things manually.I come across a lots of videos on youtube to configure graphics in codeblocks and i found all the videos are just waste of time except one video and i learnt  from that video .It was a bit difficult for me to configure graphics in codeblocks.
This is why because i was getting the libraries and header file with bug.
So i thought to create a video on this topic on my own  :How to use graphics in codeblocks video

  If you did these two things then you can use this program or concept to insert images in C++ language using graphics in Codeblocks.
Here we go:
 int main()  
   return 0;  

Description of the program:

If you are using codeblocks to make programs in graphics mode then we can make the programs in only C++ because in the graphics.h header file there is reference to iostream and if we work in C language then it will not link and then we get error in header file graphics.h.

here we have used the two important predefinded functions of graphics they are....

  • initwindow():this function is used to initialise a new window or you can say a  new window
  • readimagefile():this is the function that is used to set images in our program.
readimagefile() takes five parameters the first parameter is the name of the image with extension of the image and the rest are the co-ordinates of the screen where to set.

Thanks for visiting ...we will come with new typical programs so stay connected.

How to insert image in c language in turboc IDE

Its been very interesting as well as difficult to work with graphics in c or c++ languages.
But it will be more interesting to work with image insertion in C or C++ language.

I have already created the post to insert image in c/c++ in codeblocks IDE but now its time to achieve this using Turbo C++ IDE.

 Befor writing code we have to take care of  these points.
  • Create a  bmp(16 color Bitmap) image file using paint or any other image editor. 
  • paste that file into bin folder of turbo c where this program will be saved.
  • After pasting we will continue to write the below code.

 #include <alloc.h>  
   #include <conio.h>  
   #include <graphics.h>  
   #include <stdio.h>  
   #include <stdlib.h>  
   struct BMP  
    char Type[2];      //File type. Set to "BM".  
    unsigned long Size;   //Size in BYTES of the file.  
    unsigned long Reserved;   //Reserved. Set to zero.  
    unsigned long OffSet;  //Offset to the data.  
    unsigned long headsize; //Size of rest of header. Set to 40.  
    unsigned long Width;   //Width of bitmap in pixels.  
    unsigned long Height;   // Height of bitmap in pixels.  
    unsigned int Planes;  //Number of Planes. Set to 1.  
    unsigned int BitsPerPixel;    //Number of Bits per pixels.  
    unsigned long Compression;  //Compression. Usually set to 0.  
    unsigned long SizeImage; //Size in bytes of the bitmap.  
    unsigned long XPixelsPreMeter;   //Horizontal pixels per meter.  
    unsigned long YPixelsPreMeter;   //Vertical pixels per meter.  
    unsigned long ColorsUsed;  //Number of colors used.  
    unsigned long ColorsImportant; //Number of "important" colors.  
   int ShowBMP(int x, int y, char* FileName)  
     int b,a;  
     struct BMP Obj;  
     unsigned char* Datas;  
     int in=0;  
     unsigned char c=0;  
     FILE * fp;  
     fp = fopen(image.bmp,"rb"); //give filename of image with extension.  
     printf("Error : Unable to open file ..");  
     fread(&Obj, sizeof(Obj), 1, fp);  
     if(Obj.BitsPerPixel!=4) // This isn't a 16 color bmp we can read;  
      printf("Error : File format not supported ..");  
     Datas=(unsigned char*) calloc(Obj.Width/2+1, sizeof(unsigned char));  
      fread(Datas, sizeof(unsigned char), Obj.Width/2, fp);  
        c = (Datas[in] | 0x00) >>4;  
        c = (Datas[in] | 0xF0) & 0x0F;  
     free (Datas);  
     return 1;  
   void main()  
   int color;  
   int gd , gm ;  
   gd = VGA ; gm = VGAHI;  
   ShowBMP(0,0,"j.bmp"); /* Enter File Name Here */  

Now Run the code and you will get your image as output.

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...