Update application when a new version is available

Update application when a new version is available. The Android Market(Google Play) determine the version of the application based on the versionCode. The update of an existing application is checked by the versionCode. The versionCode should be start with “1” and increase this value by one, if you roll-out a new version of your application. When ever a change in the versionCode the Play Store will notify the user about the update.

PHP Code

{"a":"True","b":"1.5","c":"To use the application, you need to upgratde it to the latest version availbale on Google play.","d":"Due to some issues, App is under 'Maintenece Mode'. We will be right back soon."}

1. Main Activity

package com.tutorialsee;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public class MainActivity extends Activity {
    static String msg = "", error = "",_d_url = "https://play.google.com/store/apps/details?id=com.mehandi.design",versioncode = "", msgnew = "", someissues = "";
    ArrayList<HashMap<String, String>> array1 ;
    static Context context ;
    String pkgName;
    public static boolean mobileswall = false, pxx = false,    wallpapermob = false;
    String version = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        context = this ;
       
        //get mobile version
        PackageInfo pInfo = null;
        try {
            pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            version = pInfo.versionName;
        } catch (NameNotFoundException e1) {
            e1.printStackTrace();
        }
       
        VersionCheck();
       
    }

2. boxlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv_alerttxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textSize="16sp"
        android:layout_marginTop="30dp"
        android:layout_centerInParent="true"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:ems="10" >
    </TextView>

</RelativeLayout>

3. boxlayouts.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv_alerttxt"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:textSize="18sp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:ems="5" >
    </TextView>

</RelativeLayout>