Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;

import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.preference.PreferenceManager;

public class Main {
    public static boolean isUpgradedVersion(Context context) {
        SharedPreferences appSettings = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = appSettings.edit();
        int versionCode = appSettings.getInt("appVersion", -1);
        try {
            PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            int newVersion = pInfo.versionCode;
            if (versionCode != -1 && versionCode != newVersion) {
                editor.putInt("appVersion", newVersion);
                editor.commit();
                return true;
            }
        } catch (Exception e) {
        }
        ;
        return false;
    }
}