Skip to content

Commit

Permalink
move BuildUtils to WPUtils subtree, rename BuildUtils to PackageUtils…
Browse files Browse the repository at this point in the history
… and add getPackageInfo and getVersionCode methods
  • Loading branch information
maxme committed Aug 20, 2014
1 parent 10253e0 commit f464cdb
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.wordpress.android.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class PackageUtils {
/**
* Return true if Debug build. false otherwise.
*/
public static boolean isDebugBuild() {
return BuildConfig.DEBUG;
}

public static PackageInfo getPackageInfo(Context context) {
try {
PackageManager manager = context.getPackageManager();
return manager.getPackageInfo(context.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}

/**
* Return version code, or 0 if it can't be read
*/
public static int getVersionCode(Context context) {
PackageInfo packageInfo = getPackageInfo(context);
if (packageInfo != null) {
return packageInfo.versionCode;
}
return 0;
}

/**
* Return version name, or the string "0" if it can't be read
*/
public static String getVersionName(Context context) {
PackageInfo packageInfo = getPackageInfo(context);
if (packageInfo != null) {
return packageInfo.versionName;
}
return "0";
}
}

0 comments on commit f464cdb

Please sign in to comment.