From 98cc6c5497db2c2f4f7067977d49c7a305dfd0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Thu, 9 Jan 2025 19:22:54 +0000 Subject: [PATCH] Fix custom actions on sdk >= 34 --- .../externalevents/NotificationListener.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java index 8bcc2c01d..924ec9180 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -22,6 +22,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.externalevents; +import android.app.ActivityOptions; import android.app.Notification; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -243,7 +244,14 @@ public class NotificationListener extends NotificationListenerService { RemoteInput.addResultsToIntent(new RemoteInput[]{remoteInput}, localIntent, extras); actionIntent.send(context, 0, localIntent); } else { - actionIntent.send(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + final ActivityOptions activityOptions = ActivityOptions.makeBasic(); + final Bundle bundle = activityOptions.setPendingIntentBackgroundActivityStartMode(ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED) + .toBundle(); + actionIntent.send(bundle); + } else { + actionIntent.send(); + } } mActionLookup.remove(handle); } catch (final PendingIntent.CanceledException e) { @@ -500,7 +508,7 @@ public class NotificationListener extends NotificationListenerService { notificationSpec.attachedActions.add(customAction); customAction.handle = ((long) notificationSpec.getId() << 4) + notificationSpec.attachedActions.size(); mActionLookup.add((int) customAction.handle, new NotificationAction(act.actionIntent, remoteInput)); - LOG.info("Found custom action {}: {} - {} {}", notificationSpec.attachedActions.size(), (int) customAction.handle, act.title, sbn.getTag()); + LOG.info("Found custom action {}: {} - {}", notificationSpec.attachedActions.size(), (int) customAction.handle, act.title); } }