Skip to content

Commit ef29c31

Browse files
Remove NewApi suppression
1 parent fece074 commit ef29c31

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.schabi.newpipe.local.feed.notifications
22

33
import android.content.Context
44
import android.content.pm.ServiceInfo
5+
import android.os.Build
56
import android.util.Log
67
import androidx.core.app.NotificationCompat
78
import androidx.work.Constraints
@@ -84,8 +85,7 @@ class NotificationWorker(
8485
.setPriority(NotificationCompat.PRIORITY_LOW)
8586
.setContentTitle(applicationContext.getString(R.string.feed_notification_loading))
8687
.build()
87-
@Suppress("NewApi") // ServiceInfo constant is inlined
88-
val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
88+
val serviceType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC else 0
8989
setForegroundAsync(ForegroundInfo(FeedLoadService.NOTIFICATION_ID, notification, serviceType))
9090
}
9191

app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,16 @@ public boolean shouldUpdateBufferingSlot() {
167167
&& notificationBuilder.mActions.get(2).actionIntent != null);
168168
}
169169

170-
@SuppressLint("NewApi") // ServiceInfo constant is inlined
171170
public void createNotificationAndStartForeground() {
172171
if (notificationBuilder == null) {
173172
notificationBuilder = createNotification();
174173
}
175174
updateNotification();
176175

176+
final int serviceType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
177+
? ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK : 0;
177178
ServiceCompat.startForeground(player.getService(), NOTIFICATION_ID,
178-
notificationBuilder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
179+
notificationBuilder.build(), serviceType);
179180
}
180181

181182
public void cancelNotificationAndStopForeground() {

0 commit comments

Comments
 (0)