Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; public class Main { public static boolean judgeFirstIn(Context context) { SharedPreferences preferences = context.getSharedPreferences("isFirst", Context.MODE_PRIVATE); boolean isFirst = preferences.getBoolean("isFirst", true); int versionCode = preferences.getInt("versionCode", 1); if (isFirst || versionCode < getVersionCode(context)) { preferences.edit().putBoolean("isFirst", false).commit(); preferences.edit().putInt("versionCode", getVersionCode(context)).commit(); } // return isFirst; return false; } public static int getVersionCode(Context context) { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = null; try { packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return packageInfo.versionCode; } }