/* * Author: Balch * Created: 12/19/16 9:21 PM * * This file is part of MockTrade. * * MockTrade is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MockTrade is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MockTrade. If not, see <http://www.gnu.org/licenses/>. * * Copyright (C) 2016 * */ package com.balch.mocktrade.shared.utils; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; public class VersionUtils { public static String getVersion(Context context, boolean isDebug) { String version = "???"; try { PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); version = pInfo.versionName + " (" + pInfo.versionCode + ")"; if (isDebug) { version += " - DEBUG"; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return version; } }