Read versionCode from the Manifest, since BuildConfig.VERSION_CODE does not contain the correct last digit.
This commit is contained in:
@@ -28,6 +28,7 @@ import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.annotation.ChecksSdkIntAtLeast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import io.element.android.libraries.androidutils.R
|
||||
import io.element.android.libraries.androidutils.compat.getApplicationInfoCompat
|
||||
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||
@@ -47,6 +48,19 @@ fun Context.getApplicationLabel(packageName: String): String {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the versionCode from the Manifest.
|
||||
* The value is more accurate than BuildConfig.VERSION_CODE, as it is correct according to the
|
||||
* computation in the `androidComponents` block of the app build.gradle.kts file.
|
||||
* In other words, the last digit (for the architecture) will be set, whereas BuildConfig.VERSION_CODE
|
||||
* last digit will always be 0.
|
||||
*/
|
||||
fun Context.getVersionCodeFromManifest(): Long {
|
||||
return PackageInfoCompat.getLongVersionCode(
|
||||
packageManager.getPackageInfo(packageName, 0)
|
||||
)
|
||||
}
|
||||
|
||||
// ==============================================================================================================
|
||||
// Clipboard helper
|
||||
// ==============================================================================================================
|
||||
|
||||
Reference in New Issue
Block a user