How do I determine the revision number of an Android build?

六眼飞鱼酱① 提交于 2019-12-23 21:21:05

问题


I know how to get the API level, android.os.Build.VERSION.SDK_INT, but there are also several revisions of each level release, e.g. for 2.1 there's rev 1 and 2. How do I determine the revision of a build?

The reason i'd like to know this is that I have a workaround for a bug in Android 2.1 (and 2.2), and this workaround will break the moment the corresponding bug is fixed. So right now i'm in the odd position of hoping that the bug won't be fixed (at least not until I can find an answer to above question).


回答1:


I'm not sure which revision you're reffering to, but the revision you set in your manifest file you can get with the following code:

paramContext is your Context object

    PackageManager localPackageManager = paramContext.getPackageManager();
    PackageInfo localPackageInfo = localPackageManager.getPackageInfo(paramContext.getPackageName(), 0);
    String version = localPackageInfo.versionName;

If you want to extract the build version, use this code:

String version = Build.VERSION.RELEASE;


来源:https://stackoverflow.com/questions/2901722/how-do-i-determine-the-revision-number-of-an-android-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!