From 59db955493370f685281f4e09a068afd7d2eb6ef Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 27 Jul 2025 11:29:58 +0530 Subject: [PATCH 1/5] Fix new streams notification issue --- app/src/main/AndroidManifest.xml | 8 +++++++- .../local/feed/notifications/NotificationWorker.kt | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e21bb518c..efb667b22 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -98,9 +98,15 @@ - + + = Build.VERSION_CODES.Q) ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC else 0 + setForegroundAsync(ForegroundInfo(FeedLoadService.NOTIFICATION_ID, notification, serviceType)) } companion object { From b9b47fc5203a6b2cb08bb70ba51b3eb368ea579e Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 27 Jul 2025 11:58:01 +0530 Subject: [PATCH 2/5] Update manifest, startForeground call --- app/src/main/AndroidManifest.xml | 11 +++++++++-- .../newpipe/player/notification/NotificationUtil.java | 8 ++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index efb667b22..8a6b22ab3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -96,8 +96,14 @@ android:exported="false" android:label="@string/title_activity_about" /> - - + + + + @@ -431,6 +437,7 @@ diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java index 30420b0c7..e5e2544b2 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java @@ -174,12 +174,8 @@ public final class NotificationUtil { } updateNotification(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - player.getService().startForeground(NOTIFICATION_ID, notificationBuilder.build(), - ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); - } else { - player.getService().startForeground(NOTIFICATION_ID, notificationBuilder.build()); - } + ServiceCompat.startForeground(player.getService(), NOTIFICATION_ID, + notificationBuilder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); } public void cancelNotificationAndStopForeground() { From fece0741e5a1cf562e0bcfedae3aac327d7d5739 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 27 Jul 2025 12:17:44 +0530 Subject: [PATCH 3/5] Suppress NewApi --- .../newpipe/local/feed/notifications/NotificationWorker.kt | 4 ++-- .../schabi/newpipe/player/notification/NotificationUtil.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt index ad2f1055c..ca48a4243 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt @@ -2,7 +2,6 @@ package org.schabi.newpipe.local.feed.notifications import android.content.Context import android.content.pm.ServiceInfo -import android.os.Build import android.util.Log import androidx.core.app.NotificationCompat import androidx.work.Constraints @@ -85,7 +84,8 @@ class NotificationWorker( .setPriority(NotificationCompat.PRIORITY_LOW) .setContentTitle(applicationContext.getString(R.string.feed_notification_loading)) .build() - val serviceType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC else 0 + @Suppress("NewApi") // ServiceInfo constant is inlined + val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC setForegroundAsync(ForegroundInfo(FeedLoadService.NOTIFICATION_ID, notification, serviceType)) } diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java index e5e2544b2..f314f713a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java @@ -167,7 +167,7 @@ public final class NotificationUtil { && notificationBuilder.mActions.get(2).actionIntent != null); } - + @SuppressLint("NewApi") // ServiceInfo constant is inlined public void createNotificationAndStartForeground() { if (notificationBuilder == null) { notificationBuilder = createNotification(); From ef29c318b06e5875aacf765c1c1b2adbb5d49b1f Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 29 Jul 2025 06:18:27 +0530 Subject: [PATCH 4/5] Remove NewApi suppression --- .../newpipe/local/feed/notifications/NotificationWorker.kt | 4 ++-- .../schabi/newpipe/player/notification/NotificationUtil.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt index ca48a4243..ad2f1055c 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt @@ -2,6 +2,7 @@ package org.schabi.newpipe.local.feed.notifications import android.content.Context import android.content.pm.ServiceInfo +import android.os.Build import android.util.Log import androidx.core.app.NotificationCompat import androidx.work.Constraints @@ -84,8 +85,7 @@ class NotificationWorker( .setPriority(NotificationCompat.PRIORITY_LOW) .setContentTitle(applicationContext.getString(R.string.feed_notification_loading)) .build() - @Suppress("NewApi") // ServiceInfo constant is inlined - val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC + val serviceType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC else 0 setForegroundAsync(ForegroundInfo(FeedLoadService.NOTIFICATION_ID, notification, serviceType)) } diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java index f314f713a..8b7287f56 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java @@ -167,15 +167,16 @@ public final class NotificationUtil { && notificationBuilder.mActions.get(2).actionIntent != null); } - @SuppressLint("NewApi") // ServiceInfo constant is inlined public void createNotificationAndStartForeground() { if (notificationBuilder == null) { notificationBuilder = createNotification(); } updateNotification(); + final int serviceType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q + ? ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK : 0; ServiceCompat.startForeground(player.getService(), NOTIFICATION_ID, - notificationBuilder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); + notificationBuilder.build(), serviceType); } public void cancelNotificationAndStopForeground() { From 08f51abefbe40ebe49d2bf203cc489de1ab3411b Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 31 Aug 2025 22:25:12 +0530 Subject: [PATCH 5/5] Added comments --- .../newpipe/local/feed/notifications/NotificationWorker.kt | 1 + .../org/schabi/newpipe/player/notification/NotificationUtil.java | 1 + 2 files changed, 2 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt index ad2f1055c..6fe311fb0 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt @@ -85,6 +85,7 @@ class NotificationWorker( .setPriority(NotificationCompat.PRIORITY_LOW) .setContentTitle(applicationContext.getString(R.string.feed_notification_loading)) .build() + // ServiceInfo constants are not used below Android Q, so 0 is set here val serviceType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC else 0 setForegroundAsync(ForegroundInfo(FeedLoadService.NOTIFICATION_ID, notification, serviceType)) } diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java index 8b7287f56..cfd91a0ae 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java @@ -173,6 +173,7 @@ public final class NotificationUtil { } updateNotification(); + // ServiceInfo constants are not used below Android Q, so 0 is set here final int serviceType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK : 0; ServiceCompat.startForeground(player.getService(), NOTIFICATION_ID,