How do I get my application Version
任何人都可以告诉我如何获得Android应用版本?
This page has a tips on how to do it from java:
PackageManager manager = context.getPackageManager();
PackageInfo info = manager.getPackageInfo(
context.getPackageName(), 0);
String version = info.versionName;
Also, this link has official information on how to properly set up your application versioning.
I am using Android Studio, I realized I could use one line code to get this.
/*version name*/
BuildConfig.VERSION_NAME
/*version code*/
BuildConfig.VERSION_CODE
Edited:
If you are using other android libraries, make sure you import BuildConfig from your application package. This is similar to the automatically generated R class for identifying resources.
要获取应用程序信息:
PackageManager manager = this.getPackageManager();
try {
PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
String packageName = info.packageName;
int versionCode = info.versionCode;
String versionName = info.versionName;
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
}
链接地址: http://www.djcxy.com/p/90756.html
上一篇: 在代码中获取android:versionName清单元素
下一篇: 我如何获得我的应用程序版本