Skip to content

Commit f464cdb

Browse files
committed
move BuildUtils to WPUtils subtree, rename BuildUtils to PackageUtils and add getPackageInfo and getVersionCode methods
1 parent 10253e0 commit f464cdb

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.wordpress.android.util;
2+
3+
import android.content.Context;
4+
import android.content.pm.PackageInfo;
5+
import android.content.pm.PackageManager;
6+
7+
public class PackageUtils {
8+
/**
9+
* Return true if Debug build. false otherwise.
10+
*/
11+
public static boolean isDebugBuild() {
12+
return BuildConfig.DEBUG;
13+
}
14+
15+
public static PackageInfo getPackageInfo(Context context) {
16+
try {
17+
PackageManager manager = context.getPackageManager();
18+
return manager.getPackageInfo(context.getPackageName(), 0);
19+
} catch (PackageManager.NameNotFoundException e) {
20+
return null;
21+
}
22+
}
23+
24+
/**
25+
* Return version code, or 0 if it can't be read
26+
*/
27+
public static int getVersionCode(Context context) {
28+
PackageInfo packageInfo = getPackageInfo(context);
29+
if (packageInfo != null) {
30+
return packageInfo.versionCode;
31+
}
32+
return 0;
33+
}
34+
35+
/**
36+
* Return version name, or the string "0" if it can't be read
37+
*/
38+
public static String getVersionName(Context context) {
39+
PackageInfo packageInfo = getPackageInfo(context);
40+
if (packageInfo != null) {
41+
return packageInfo.versionName;
42+
}
43+
return "0";
44+
}
45+
}

0 commit comments

Comments
 (0)