package com.xty.network.utils

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

object  AppUtils {

   fun getVersionCode( context: Context) :Int{
        var  packageInfo = getPackagesInfo(context)
       if (packageInfo != null){
           return packageInfo!!.versionCode
       }else{
           return  -1
       }
    }

    fun  getPackagesInfo( context:Context) : PackageInfo ?{
        try {
            return context.packageManager.getPackageInfo(context.packageName, 0);
        } catch ( e: PackageManager.NameNotFoundException) {
            e.printStackTrace();
        }
        return null;
    }


     fun getPackageVersionName(context:Context):String {
         var  packageInfo = getPackagesInfo(context)
         if (packageInfo != null){
             return packageInfo!!.versionName
         }else{
             return  ""
         }
    }

}