I'd like to simply display my version name on my login screen, however, it's always returning null. I've defined my versionName in my app's gradle build as follows:
defaultConfig {
applicationId "com.maplesyrupindustries.j.airportmeet"
minSdkVersion 19
targetSdkVersion 24
versionCode 7
versionName "1.0.6"
multiDexEnabled true
}
And I am calling it in my login's onCreate:
String build = BuildConfig.VERSION_NAME;
Log.e(TAG, BuildConfig.VERSION_NAME);
tvVersion.setText("Alpha " + build);
Yet, the build string is always empty. What gives?
Please try this
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;//Version Name
int verCode = pInfo.versionCode;//Version Code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With