From 1092e1b10ac2600b8bd63cad6e590ffb8e6e23aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 30 Apr 2022 20:24:34 +0100 Subject: [PATCH] Unset notification color for Android 12+ --- .../freeyourgadget/gadgetbridge/GBApplication.java | 3 +++ .../nodomain/freeyourgadget/gadgetbridge/util/GB.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 6282ebcac..35f4b1f6a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -380,6 +380,9 @@ public class GBApplication extends Application { return VERSION.SDK_INT >= Build.VERSION_CODES.Q; } + public static boolean isRunningTwelveOrLater() { + return VERSION.SDK_INT >= 31; // Build.VERSION_CODES.S, but our target SDK is lower + } public static boolean isRunningPieOrLater() { return VERSION.SDK_INT >= Build.VERSION_CODES.P; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java index 5bc9b1fc3..d2cbd09bb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java @@ -151,10 +151,13 @@ public class GB { .setContentText(text) .setSmallIcon(connected ? device.getNotificationIconConnected() : device.getNotificationIconDisconnected()) .setContentIntent(getContentIntent(context)) - .setColor(context.getResources().getColor(R.color.accent)) .setShowWhen(false) .setOngoing(true); + if (!GBApplication.isRunningTwelveOrLater()) { + builder.setColor(context.getResources().getColor(R.color.accent)); + } + Intent deviceCommunicationServiceIntent = new Intent(context, DeviceCommunicationService.class); if (connected) { deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_DISCONNECT); @@ -187,9 +190,13 @@ public class GB { .setContentText(text) .setSmallIcon(R.drawable.ic_notification_disconnected) .setContentIntent(getContentIntent(context)) - .setColor(context.getResources().getColor(R.color.accent)) .setShowWhen(false) .setOngoing(true); + + if (!GBApplication.isRunningTwelveOrLater()) { + builder.setColor(context.getResources().getColor(R.color.accent)); + } + if (GBApplication.getPrefs().getString("last_device_address", null) != null) { Intent deviceCommunicationServiceIntent = new Intent(context, DeviceCommunicationService.class); deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_CONNECT);