跳到主要內容

Android 取得版本資訊

使用 PackageInfo 取得版本資訊

PackageInfo pInfo = null;
try {
    pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
} catch (Exception ex) {

}

int versionCode = pInfo.versionCode;
String versionName = pInfo.versionName;

如果有掛載 Gradle plugin 或是 使用 Android Studio 0.7.0 以上,就可以用 BuildConfig 取得版本資訊

int versionCode = BuildConfig.VERSION_CODE;
String versionName = BuildConfig.VERSION_NAME;


留言

這個網誌中的熱門文章

What is phpize

What is phpize According to the PHP official document : The phpize command is used to prepare the build environment for a PHP extension. If you need to build such an extension that from github or another code repositories, you can use  build tools to perform the build manually.