From 7d42da8c345bf4282c662e949313e6c8aba517a5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 21 Feb 2023 09:25:43 +0100 Subject: [PATCH] Android 7+: do not repeat app name in notification --- .../ForegroundServiceNotification.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/im/conversations/android/notification/ForegroundServiceNotification.java b/app/src/main/java/im/conversations/android/notification/ForegroundServiceNotification.java index de3d89332..0fc32edc9 100644 --- a/app/src/main/java/im/conversations/android/notification/ForegroundServiceNotification.java +++ b/app/src/main/java/im/conversations/android/notification/ForegroundServiceNotification.java @@ -23,9 +23,18 @@ public class ForegroundServiceNotification { public Notification build(final ConnectionPool.Summary summary) { final Notification.Builder builder = new Notification.Builder(service); - builder.setContentTitle(service.getString(R.string.app_name)); - builder.setContentText( - service.getString(R.string.connected_accounts, summary.connected, summary.total)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + // starting with Android 7 the app name is displayed as part of the notification + // this means we do not have to repeat it in the 'content title' + builder.setContentTitle( + service.getString( + R.string.connected_accounts, summary.connected, summary.total)); + } else { + builder.setContentTitle(service.getString(R.string.app_name)); + builder.setContentText( + service.getString( + R.string.connected_accounts, summary.connected, summary.total)); + } builder.setContentIntent(buildPendingIntent()); builder.setWhen(0) .setPriority(Notification.PRIORITY_MIN)