Target
如何取得 APP version name。
Action Item
- Function
- How to use
Quick Start
Function
Get version name function1
2
3
4
5
6
7
8
9
10
11
12
13private 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 Activity1
getVersionName(MainActivity.this);