android,kotlin2022. 3. 7. 17:08

[kotlin]context로 package version name 방법

 

fun getVersionName(context : Context) : String
{
    var versionName = "unknown"
    try
    {
        versionName =
            context.packageManager.getPackageInfo(context.packageName, 0).versionName
    } catch (e: PackageManager.NameNotFoundException) {
        L.e(e)
    }
    return versionName
}

 

Posted by thdeodls85