From ef29c318b06e5875aacf765c1c1b2adbb5d49b1f Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 29 Jul 2025 06:18:27 +0530 Subject: [PATCH] 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() {