Fix application package name following AND_3
This commit is contained in:
parent
5dbeb07dde
commit
28221ee172
|
@ -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,7 +10,16 @@ private const val U_TAG = "PackageUtils"
|
|||
|
||||
fun Context.getApplicationName(packageId: String): String? {
|
||||
try {
|
||||
val ai = if (Build.VERSION.SDK_INT >= 33) {
|
||||
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(
|
||||
|
@ -19,9 +29,4 @@ fun Context.getApplicationName(packageId: String): String? {
|
|||
} else {
|
||||
this.packageManager.getApplicationInfo(packageId, 0)
|
||||
}
|
||||
return this.packageManager.getApplicationLabel(ai).toString()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
Log.e(U_TAG, "Could not resolve app name", e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue