Fix application package name following AND_3

This commit is contained in:
sim 2024-10-28 11:16:07 +00:00
parent 5dbeb07dde
commit 28221ee172

View File

@ -1,6 +1,7 @@
package org.unifiedpush.distributor.nextpush.utils
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.os.Build
import android.util.Log
@ -9,19 +10,23 @@ private const val U_TAG = "PackageUtils"
fun Context.getApplicationName(packageId: String): String? {
try {
val ai = if (Build.VERSION.SDK_INT >= 33) {
this.packageManager.getApplicationInfo(
packageId,
PackageManager.ApplicationInfoFlags.of(
PackageManager.GET_META_DATA.toLong()
)
)
} else {
this.packageManager.getApplicationInfo(packageId, 0)
}
val ai = appInfoForMetadata(packageId)
return this.packageManager.getApplicationLabel(ai).toString()
} catch (e: PackageManager.NameNotFoundException) {
Log.e(U_TAG, "Could not resolve app name", e)
return null
}
}
fun Context.appInfoForMetadata(packageId: String): ApplicationInfo {
return if (Build.VERSION.SDK_INT >= 33) {
this.packageManager.getApplicationInfo(
packageId,
PackageManager.ApplicationInfoFlags.of(
PackageManager.GET_META_DATA.toLong()
)
)
} else {
this.packageManager.getApplicationInfo(packageId, 0)
}
}