15

In the Android manifest file, there is a field that specifies the application version.

How I can read that value programmatically?

3 Answers 3

36

You can get access to that information through the PackageInfo class:

PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
Log.d("pinfoCode",pinfo.versionCode);
Log.d("pinfoName",pinfo.versionName);
1

Call GetApplicationContext().PackageManager().getPackageInfo(). The PackageInfo object it returns will have what you need.

0
try {
    final String packageName = context.getPackageName();
    PackageInfo packageInfo = context.getApplicationContext().getPackageManager().getPackageInfo(packageName, 0);
    final int iconid = packageInfo.applicationInfo.icon; // for example

    // etc
} catch (android.content.pm.PackageManager.NameNotFoundException e) {}

Not the answer you're looking for? Browse other questions tagged or ask your own question.