File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
WordPressUtils/src/main/java/org/wordpress/android/util Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments