Skip to content

Commit

Permalink
#1387 fix: launching app shortcuts works again on Android 14+
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Jan 12, 2025
1 parent ceecc02 commit 20f3802
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.github.sds100.keymapper.system.apps

import android.app.ActivityOptions
import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Bundle
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
Expand Down Expand Up @@ -79,8 +81,7 @@ class AndroidAppShortcutAdapter(context: Context) : AppShortcutAdapter {
}
}

override fun createShortcutResultIntent(shortcut: ShortcutInfoCompat): Intent =
ShortcutManagerCompat.createShortcutResultIntent(ctx, shortcut)
override fun createShortcutResultIntent(shortcut: ShortcutInfoCompat): Intent = ShortcutManagerCompat.createShortcutResultIntent(ctx, shortcut)

override fun getShortcutName(info: AppShortcutInfo): Result<String> {
try {
Expand Down Expand Up @@ -117,7 +118,18 @@ class AndroidAppShortcutAdapter(context: Context) : AppShortcutAdapter {
val flags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
val pendingIntent = PendingIntent.getActivity(ctx, 0, intent, flags)

pendingIntent.send()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
val bundle = ActivityOptions.makeBasic()
.setPendingIntentBackgroundActivityStartMode(
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED,
)
.toBundle()

pendingIntent.send(bundle)
} else {
pendingIntent.send()
}

return Success(Unit)
} catch (e: SecurityException) {
return Error.InsufficientPermissionsToOpenAppShortcut
Expand Down

0 comments on commit 20f3802

Please sign in to comment.