Starting from API level 33 the getPackageInfo(String, int)
method of PackageManager class is deprecated. Documentation suggests to use getPackageInfo(String, PackageInfoFlags)
instead. But that function is only available from API level 33.
My current code:
val pInfo = context.packageManager.getPackageInfo(context.packageName, 0)
Is this how it should be now?
val pInfo = context.getPackageInfo()
@Suppress("DEPRECATION")
fun Context.getPackageInfo(): PackageInfo {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
} else {
packageManager.getPackageInfo(packageName, 0)
}
}