1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-09-10 14:55:59 +00:00

Merge pull request #12471 from Isira-Seneviratne/Fix-notifications

Fix foreground service issues
This commit is contained in:
Isira Seneviratne
2025-09-01 05:05:47 +05:30
committed by GitHub
3 changed files with 26 additions and 11 deletions

View File

@@ -96,11 +96,23 @@
android:exported="false" android:exported="false"
android:label="@string/title_activity_about" /> android:label="@string/title_activity_about" />
<service android:name=".local.subscription.services.SubscriptionsImportService" /> <service
<service android:name=".local.subscription.services.SubscriptionsExportService" /> android:name=".local.subscription.services.SubscriptionsImportService"
<service android:name=".local.feed.service.FeedLoadService"
android:foregroundServiceType="dataSync" /> android:foregroundServiceType="dataSync" />
<service
android:name=".local.subscription.services.SubscriptionsExportService"
android:foregroundServiceType="dataSync" />
<service
android:name=".local.feed.service.FeedLoadService"
android:foregroundServiceType="dataSync" />
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
<activity <activity
android:name=".PanicResponderActivity" android:name=".PanicResponderActivity"
android:exported="true" android:exported="true"
@@ -425,6 +437,7 @@
</activity> </activity>
<service <service
android:name=".RouterActivity$FetcherService" android:name=".RouterActivity$FetcherService"
android:foregroundServiceType="dataSync"
android:exported="false" /> android:exported="false" />
<!-- opting out of sending metrics to Google in Android System WebView --> <!-- opting out of sending metrics to Google in Android System WebView -->

View File

@@ -1,6 +1,8 @@
package org.schabi.newpipe.local.feed.notifications package org.schabi.newpipe.local.feed.notifications
import android.content.Context import android.content.Context
import android.content.pm.ServiceInfo
import android.os.Build
import android.util.Log import android.util.Log
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.work.Constraints import androidx.work.Constraints
@@ -83,7 +85,9 @@ class NotificationWorker(
.setPriority(NotificationCompat.PRIORITY_LOW) .setPriority(NotificationCompat.PRIORITY_LOW)
.setContentTitle(applicationContext.getString(R.string.feed_notification_loading)) .setContentTitle(applicationContext.getString(R.string.feed_notification_loading))
.build() .build()
setForegroundAsync(ForegroundInfo(FeedLoadService.NOTIFICATION_ID, notification)) // 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))
} }
companion object { companion object {

View File

@@ -167,19 +167,17 @@ public final class NotificationUtil {
&& notificationBuilder.mActions.get(2).actionIntent != null); && notificationBuilder.mActions.get(2).actionIntent != null);
} }
public void createNotificationAndStartForeground() { public void createNotificationAndStartForeground() {
if (notificationBuilder == null) { if (notificationBuilder == null) {
notificationBuilder = createNotification(); notificationBuilder = createNotification();
} }
updateNotification(); updateNotification();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // ServiceInfo constants are not used below Android Q, so 0 is set here
player.getService().startForeground(NOTIFICATION_ID, notificationBuilder.build(), final int serviceType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); ? ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK : 0;
} else { ServiceCompat.startForeground(player.getService(), NOTIFICATION_ID,
player.getService().startForeground(NOTIFICATION_ID, notificationBuilder.build()); notificationBuilder.build(), serviceType);
}
} }
public void cancelNotificationAndStopForeground() { public void cancelNotificationAndStopForeground() {