Is there any way to know dynamically and programmatically the versionCode of an Android application??
I don´t know... maybe something like
 getApplicationContext.getVersionCode();
Thank you very much.
Is there any way to know dynamically and programmatically the versionCode of an Android application??
I don´t know... maybe something like
 getApplicationContext.getVersionCode();
Thank you very much.
 
    
     
    
    If you're using gradle (default in AndroidStudio) you can:
BuildConfig.VERSION_CODE
 
    
    You find the following from using this code
 public int getVersionCode() {
    int v = 0;
    try {
        v = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
    }
    return v;
}
Class Required
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
 
    
    This should be surrounded by a try...catch.
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;
versionCode = pInfo.versionCode;
 
    
    try this
BuildConfig.VERSION_CODE
and import
import com.<your_pakcage_name>.BuildConfig;
