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

Commit fa1149d1 authored by Sara Ting's avatar Sara Ting Committed by Android (Google) Code Review
Browse files

Merge "Adding util method to get release version." into ics-ub-calendar-aqua

parents 78db24d5 dacfb663
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;
    }
}