Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(android) fix crash when starting foreground service

Saúl Ibarra Corretgé23b91c033640
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java
index 1dacf3f3cd..df94f4264d 100644
--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java
@@ -51,11 +51,20 @@ public class JitsiMeetOngoingConferenceService extends Service
intent.setAction(Action.START.getName());
ComponentName componentName;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- componentName = context.startForegroundService(intent);
- } else {
- componentName = context.startService(intent);
+
+ try {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ componentName = context.startForegroundService(intent);
+ } else {
+ componentName = context.startService(intent);
+ }
+ } catch (RuntimeException e) {
+ // Avoid crashing due to ForegroundServiceStartNotAllowedException (API level 31).
+ // See: https://developer.android.com/guide/components/foreground-services#background-start-restrictions
+ JitsiMeetLogger.w(TAG + " Ongoing conference service not started", e);
+ return;
}
+
if (componentName == null) {
JitsiMeetLogger.w(TAG + " Ongoing conference service not started");
}