fix(android) Use startForegroundService and do not delete the notification channel until onDestroy (#4105)

See https://developer.android.com/develop/background-work/services/foreground-services\#fgs-prerequisites
    See rationale here https://stackoverflow.com/questions/45525214/are-there-any-benefits-to-using-context-startforegroundserviceintent-instead-o
    Deleting the notification channel while the foreground service is still running is not permitted.
This commit is contained in:
Paul Rinaldi
2024-10-03 01:23:17 -05:00
committed by GitHub
parent 149924ffcb
commit 40872f5ea7
2 changed files with 10 additions and 4 deletions

View File

@@ -975,7 +975,11 @@ public class ReactExoplayerView extends FrameLayout implements
Intent intent = new Intent(themedReactContext, VideoPlaybackService.class);
intent.setAction(MediaSessionService.SERVICE_INTERFACE);
themedReactContext.startService(intent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
themedReactContext.startForegroundService(intent);
} else {
themedReactContext.startService(intent);
}
int flags;
if (Build.VERSION.SDK_INT >= 29) {