-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move BuildUtils to WPUtils subtree, rename BuildUtils to PackageUtils…
… and add getPackageInfo and getVersionCode methods
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
WordPressUtils/src/main/java/org/wordpress/android/util/PackageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |