|
1 | 1 | package io.github.sds100.keymapper.system.apps |
2 | 2 |
|
| 3 | +import android.app.ActivityOptions |
3 | 4 | import android.app.PendingIntent |
4 | 5 | import android.content.ComponentName |
5 | 6 | import android.content.Context |
6 | 7 | import android.content.Intent |
7 | 8 | import android.content.pm.PackageManager |
8 | 9 | import android.graphics.drawable.Drawable |
| 10 | +import android.os.Build |
9 | 11 | import android.os.Bundle |
10 | 12 | import androidx.core.content.pm.ShortcutInfoCompat |
11 | 13 | import androidx.core.content.pm.ShortcutManagerCompat |
@@ -79,8 +81,7 @@ class AndroidAppShortcutAdapter(context: Context) : AppShortcutAdapter { |
79 | 81 | } |
80 | 82 | } |
81 | 83 |
|
82 | | - override fun createShortcutResultIntent(shortcut: ShortcutInfoCompat): Intent = |
83 | | - ShortcutManagerCompat.createShortcutResultIntent(ctx, shortcut) |
| 84 | + override fun createShortcutResultIntent(shortcut: ShortcutInfoCompat): Intent = ShortcutManagerCompat.createShortcutResultIntent(ctx, shortcut) |
84 | 85 |
|
85 | 86 | override fun getShortcutName(info: AppShortcutInfo): Result<String> { |
86 | 87 | try { |
@@ -117,7 +118,18 @@ class AndroidAppShortcutAdapter(context: Context) : AppShortcutAdapter { |
117 | 118 | val flags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT |
118 | 119 | val pendingIntent = PendingIntent.getActivity(ctx, 0, intent, flags) |
119 | 120 |
|
120 | | - pendingIntent.send() |
| 121 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { |
| 122 | + val bundle = ActivityOptions.makeBasic() |
| 123 | + .setPendingIntentBackgroundActivityStartMode( |
| 124 | + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED, |
| 125 | + ) |
| 126 | + .toBundle() |
| 127 | + |
| 128 | + pendingIntent.send(bundle) |
| 129 | + } else { |
| 130 | + pendingIntent.send() |
| 131 | + } |
| 132 | + |
121 | 133 | return Success(Unit) |
122 | 134 | } catch (e: SecurityException) { |
123 | 135 | return Error.InsufficientPermissionsToOpenAppShortcut |
|
0 commit comments