Cannot get versionName from AndroidManifest.xml?

By | June 3, 2017

If you are running code like this:

try {
    PackageInfo myInfo = getPackageManager().getPackageInfo(getPackageName(),0);
    versionName = myInfo.versionName;
    verCode = myInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
}

TextView myText = (TextView)findViewById(R.id.textView2);
myText.setText(versionName + " - " + verCode);

but the output is not what you are expecting, the chances are you are using gradle to build your project. In fact, I can probably guarantee it. Look in your gradle file and you should see the values being pulled from there.

Leave a Reply

Your email address will not be published. Required fields are marked *