From bb1b1e951182369d564118b11d5be460efbfd915 Mon Sep 17 00:00:00 2001 From: Rafael M Date: Tue, 26 Jul 2022 14:32:08 +0200 Subject: [PATCH] wrap whole forceForeground in try-catch block --- .../react/MusicControlNotification.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/tanguyantoine/react/MusicControlNotification.java b/android/src/main/java/com/tanguyantoine/react/MusicControlNotification.java index 74ba89fa..4473a582 100644 --- a/android/src/main/java/com/tanguyantoine/react/MusicControlNotification.java +++ b/android/src/main/java/com/tanguyantoine/react/MusicControlNotification.java @@ -234,20 +234,17 @@ public IBinder onBind(Intent intent) { public void forceForeground() { // API lower than 26 do not need this work around. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Intent intent = new Intent(MusicControlNotification.NotificationService.this, - MusicControlNotification.NotificationService.class); - // service has already been initialized. - // startForeground method should be called within 5 seconds. - ContextCompat.startForegroundService(MusicControlNotification.NotificationService.this, intent); + try { + Intent intent = new Intent(MusicControlNotification.NotificationService.this, + MusicControlNotification.NotificationService.class); + // service has already been initialized. + // startForeground method should be called within 5 seconds. + ContextCompat.startForegroundService(MusicControlNotification.NotificationService.this, intent); - if (MusicControlModule.INSTANCE == null) { - try { + if (MusicControlModule.INSTANCE == null) { MusicControlModule.INSTANCE.init(); - } catch (Exception ex) { - ex.printStackTrace(); } - } - try { + notification = MusicControlModule.INSTANCE.notification .prepareNotification(MusicControlModule.INSTANCE.nb, false); // call startForeground just after startForegroundService.