From caed9022877d081a478dc8cd78b76057b89b9e07 Mon Sep 17 00:00:00 2001 From: Eoin <33495030+eoinoreilly30@users.noreply.github.com> Date: Mon, 16 Feb 2026 04:21:54 +0000 Subject: [PATCH] Implement error handling in foreground service methods Added error handling for starting foreground service. --- .../DailyOngoingMeetingForegroundService.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/daily/reactlibrary/DailyOngoingMeetingForegroundService.java b/android/src/main/java/com/daily/reactlibrary/DailyOngoingMeetingForegroundService.java index 5330bd2..788d8f2 100644 --- a/android/src/main/java/com/daily/reactlibrary/DailyOngoingMeetingForegroundService.java +++ b/android/src/main/java/com/daily/reactlibrary/DailyOngoingMeetingForegroundService.java @@ -10,6 +10,7 @@ import android.content.Intent; import android.os.Build; import android.os.IBinder; +import android.util.Log; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; @@ -38,7 +39,11 @@ public static void start(Class activityClass, String title, intent.putExtra(EXTRA_TITLE, title); intent.putExtra(EXTRA_SUBTITLE, subtitle); intent.putExtra(EXTRA_ICON_NAME, iconName); - ContextCompat.startForegroundService(context, intent); + try { + ContextCompat.startForegroundService(context, intent); + } catch (Exception e) { + Log.e(TAG, "Failed to start foreground service: " + e.getMessage(), e); + } } public static void stop(Context context) { @@ -86,7 +91,12 @@ public int onStartCommand(Intent intent, int flags, int startId) { .setOnlyAlertOnce(true) .build(); - startForeground(NOTIFICATION_ID, notification); + try { + startForeground(NOTIFICATION_ID, notification); + } catch (Exception e) { + Log.e(TAG, "Failed to promote service to foreground: " + e.getMessage(), e); + stopSelf(); + } return START_NOT_STICKY; }