Android get version name

Target

如何取得 APP version name。

Action Item

  1. Function
  2. How to use

Quick Start

Function

Get version name function

1
2
3
4
5
6
7
8
9
10
11
12
13
private String getVersionName(Context context) {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo;
String result = "";

try {
packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
result = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return result;
}

Hot to use

Input -> Now to use Activity

1
getVersionName(MainActivity.this);

Reference

  1. http://blog.csdn.net/shenyuanqing/article/details/47445959
文章目录
  1. 1. Target
  2. 2. Action Item
  3. 3. Quick Start
    1. 3.1. Function
    2. 3.2. Hot to use
  4. 4. Reference
,