开发者

How can I read the app version defined in the manifest file programmatically?

In the Android manifest file, there is a field that s开发者_JAVA技巧pecifies the application version.

How I can read that value programmatically?


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);


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


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) {}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜