VersionCodeUtils.java
1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.hjx.personalcenter.util;
import android.content.Context;
import android.content.pm.PackageManager;
import com.hjx.personalcenter.activity.MyApplication;
/**
* Created by liujiaqi on 2018/4/11.
*/
public class VersionCodeUtils {
/**
* 获取当前本地apk的版本
*
* @return
*/
public static int getVersionCode() {
int versionCode = 0;
try {
//获取软件版本号,对应AndroidManifest.xml下android:versionCode
versionCode = MyApplication.getInstance().getPackageManager().
getPackageInfo(MyApplication.getInstance().getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionCode;
}
/**
* 获取版本号名称
*
* @return
*/
public static String getVerName() {
String verName = "";
try {
verName = MyApplication.getInstance().getPackageManager().
getPackageInfo(MyApplication.getInstance().getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return verName;
}
}