-
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.
Merge pull request #1764 from wordpress-mobile/issue/1713-send-versio…
…n-code-to-mixpanel fix #1713 send version code to mixpanel
- Loading branch information
Showing
3 changed files
with
47 additions
and
16 deletions.
There are no files selected for viewing
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
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"; | ||
} | ||
} |
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