@@ -1464,6 +1464,10 @@ private void enterForeground(String content, long chronometerLength, boolean ong
14641464 builder = new Notification .Builder (this , SDL_NOTIFICATION_CHANNEL_ID );
14651465 }
14661466
1467+ if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
1468+ builder .setForegroundServiceBehavior (Notification .FOREGROUND_SERVICE_IMMEDIATE );
1469+ }
1470+
14671471 if (0 != (getApplicationInfo ().flags & ApplicationInfo .FLAG_DEBUGGABLE )) { //If we are in debug mode, include what app has the router service open
14681472 ComponentName name = new ComponentName (this , this .getClass ());
14691473 builder .setContentTitle ("SDL: " + name .getPackageName ());
@@ -1534,12 +1538,22 @@ private void enterForeground(String content, long chronometerLength, boolean ong
15341538 private void safeStartForeground (int id , Notification notification ) {
15351539 try {
15361540 if (notification == null ) {
1537- //Try the NotificationCompat this time in case there was a previous error
1538- NotificationCompat .Builder builder =
1539- new NotificationCompat .Builder (this , SDL_NOTIFICATION_CHANNEL_ID )
1541+ if ( android . os . Build . VERSION . SDK_INT >= android . os . Build . VERSION_CODES . S ) {
1542+ Notification .Builder builder =
1543+ new Notification .Builder (this , SDL_NOTIFICATION_CHANNEL_ID )
15401544 .setContentTitle ("SmartDeviceLink" )
1541- .setContentText ("Service Running" );
1542- notification = builder .build ();
1545+ .setContentText ("Service Running" )
1546+ .setForegroundServiceBehavior (Notification .FOREGROUND_SERVICE_IMMEDIATE );
1547+ notification = builder .build ();
1548+ } else {
1549+ //Try the NotificationCompat this time in case there was a previous error
1550+ NotificationCompat .Builder builder =
1551+ new NotificationCompat .Builder (this , SDL_NOTIFICATION_CHANNEL_ID )
1552+ .setContentTitle ("SmartDeviceLink" )
1553+ .setContentText ("Service Running" );
1554+
1555+ notification = builder .build ();
1556+ }
15431557 }
15441558 startForeground (id , notification );
15451559 DebugTool .logInfo (TAG , "Entered the foreground - " + System .currentTimeMillis ());
@@ -3758,6 +3772,10 @@ private void notifySppError() {
37583772 } else {
37593773 builder = new Notification .Builder (getApplicationContext (), TransportConstants .SDL_ERROR_NOTIFICATION_CHANNEL_ID );
37603774 }
3775+
3776+ if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
3777+ builder .setForegroundServiceBehavior (Notification .FOREGROUND_SERVICE_IMMEDIATE );
3778+ }
37613779 ComponentName name = new ComponentName (this , this .getClass ());
37623780 if (0 != (getApplicationInfo ().flags & ApplicationInfo .FLAG_DEBUGGABLE )) { //If we are in debug mode, include what app has the router service open
37633781 builder .setContentTitle ("SDL: " + name .getPackageName ());
0 commit comments