package com.grkj.iscs.util

import android.content.Context
import android.content.pm.PackageManager

/**
 * App工具类
 */
object AppUtils {

    /**
     * 获取版本号
     *
     * @return 当前应用的VersionName
     */
    fun getPkgVerName(context: Context): String? {
        return try {
            val manager: PackageManager = context.packageManager
            val info =
                manager.getPackageInfo(context.packageName!!, 0) //PackageManager.GET_CONFIGURATIONS
            info.versionName
        } catch (e: Exception) {
            e.printStackTrace()
            null
        }
    }

    /**
     * 获取VersionCode
     *
     * @return 当前应用的VersionCode
     */
    fun getPkgVerCode(context: Context): Int {
        return try {
            val manager: PackageManager = context.packageManager
            val info = manager.getPackageInfo(context.packageName!!, 0)
            info.versionCode
        } catch (e: Exception) {
            e.printStackTrace()
            -1
        }
    }
}