Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dacfb663 authored by Sara Ting's avatar Sara Ting
Browse files

Adding util method to get release version.

Change-Id: I7b2f7ad1d179135aab211dabce5e64dcbe924f1b
parent a6ff5f05
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.MatrixCursor;
@@ -122,6 +123,7 @@ public class Utils {
    private static final TimeZoneUtils mTZUtils = new TimeZoneUtils(SHARED_PREFS_NAME);
    private static boolean mAllowWeekForDetailView = false;
    private static long mTardis = 0;
    private static String sVersion = null;

    /**
     * Returns whether the SDK is the Jellybean release or later.
@@ -1497,4 +1499,20 @@ public class Utils {

        return s;
    }

    /**
     * Return the app version code.
     */
    public static String getVersionCode(Context context) {
        if (sVersion == null) {
            try {
                sVersion = context.getPackageManager().getPackageInfo(
                        context.getPackageName(), 0).versionName;
            } catch (PackageManager.NameNotFoundException e) {
                // Can't find version; just leave it blank.
                Log.e(TAG, "Error finding package " + context.getApplicationInfo().packageName);
            }
        }
        return sVersion;
    }
}