How To Check New Version Of Application Android Code

private int _nVersionCode = 0;	
private boolean _bNewVersion = false;
 
 
// onCreate
     	 _nVersionCode   = this.getPackageManager()
     	.getPackageInfo(this.getPackageName(), 0).versionCode;
     	Log.d(String.valueOf(_nVersionCode), "versionCode");
 
// onStart loadPreferences
 public void loadPreferences() {
			//SharedPreferences settings = getSharedPreferences(F.PREFERENCES_NAME, 0);
			SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
		int nOldVersionCode =	settings.getInt("_nVersionCode",  0);// old vesion
		if(_nVersionCode > nOldVersionCode)
			_bNewVersion = true;
	}
 
// onDestroy savePreferences	
	public void savePreferences() {
			SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
			SharedPreferences.Editor editor = settings.edit();
			editor.putInt("_nVersionCode", _nVersionCode); // save current version code
			editor.commit();
	}
This entry was posted in Android Examples Code and tagged . Bookmark the permalink.


Comments are closed.



2,440 views