From 9f2da9cdc7fa7ef6f554b72aa6db0a4fe647beed Mon Sep 17 00:00:00 2001 From: Elijah Whang <59347000+ewhang5@users.noreply.github.com> Date: Tue, 9 Jul 2024 13:22:14 -0500 Subject: [PATCH] actions: less warnings is more (fixes #3775) (#3782) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../org/ole/planet/myplanet/utilities/VersionUtils.kt | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 10a26fc456..6e53b5b014 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1664 - versionName "0.16.64" + versionCode 1665 + versionName "0.16.65" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/VersionUtils.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/VersionUtils.kt index a4ae1ebbc2..3d987fd3ab 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/VersionUtils.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/VersionUtils.kt @@ -2,14 +2,21 @@ package org.ole.planet.myplanet.utilities import android.content.Context import android.content.pm.PackageManager +import android.os.Build import android.provider.Settings +import androidx.core.content.pm.PackageInfoCompat.getLongVersionCode object VersionUtils { @JvmStatic fun getVersionCode(context: Context): Int { try { val pInfo = context.packageManager.getPackageInfo(context.packageName, 0) - return pInfo.versionCode + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + return getLongVersionCode(pInfo).toInt() + } else { + @Suppress("DEPRECATION") + return pInfo.versionCode + } } catch (e: PackageManager.NameNotFoundException) { e.printStackTrace() }