Fix custom actions on sdk >= 34

This commit is contained in:
José Rebelo 2025-01-09 19:22:54 +00:00
parent 965e22bf34
commit 98cc6c5497

View File

@ -22,6 +22,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.externalevents;
import android.app.ActivityOptions;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
@ -242,9 +243,16 @@ public class NotificationListener extends NotificationListenerService {
extras.putCharSequence(remoteInput.getResultKey(), reply);
RemoteInput.addResultsToIntent(new RemoteInput[]{remoteInput}, localIntent, extras);
actionIntent.send(context, 0, localIntent);
} else {
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) {
LOG.warn("replyToLastNotification error", 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);
}
}