Avoid using IconCompat.createFromIcon() that doesn't support bitmap icon

This commit is contained in:
残页 2023-07-13 09:29:47 +08:00 committed by John Wu
parent 7ad77a14ae
commit d390ca2fdf

View File

@ -31,7 +31,7 @@ object Shortcuts {
val info = ShortcutInfoCompat.Builder(context, Const.Nav.HOME)
.setShortLabel(context.getString(R.string.magisk))
.setIntent(intent)
.setIcon(IconCompat.createFromIcon(context, context.getIcon(R.drawable.ic_launcher)))
.setIcon(context.getIconCompat(R.drawable.ic_launcher))
.build()
ShortcutManagerCompat.requestPinShortcut(context, info, null)
}
@ -47,6 +47,18 @@ object Shortcuts {
}
}
private fun Context.getIconCompat(id: Int): IconCompat {
return if (isRunningAsStub) {
val bitmap = getBitmap(id)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
IconCompat.createWithAdaptiveBitmap(bitmap)
else
IconCompat.createWithBitmap(bitmap)
} else {
IconCompat.createWithResource(this, id)
}
}
@RequiresApi(api = 25)
private fun getShortCuts(context: Context): List<ShortcutInfo> {
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)