Skip to content

Commit

Permalink
wrap whole forceForeground in try-catch block
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelmaeuer committed Jul 26, 2022
1 parent 7336c30 commit bb1b1e9
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit bb1b1e9

Please sign in to comment.