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
1 changed files with 15 additions and 10 deletions

View File

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