11package com .sdl .hellosdlandroid ;
22
3+ import android .app .PendingIntent ;
34import android .content .Context ;
45import android .content .Intent ;
56import android .os .Build ;
67
78import com .smartdevicelink .transport .SdlBroadcastReceiver ;
89import com .smartdevicelink .transport .SdlRouterService ;
10+ import com .smartdevicelink .transport .TransportConstants ;
911import com .smartdevicelink .util .DebugTool ;
1012
1113public class SdlReceiver extends SdlBroadcastReceiver {
@@ -16,17 +18,24 @@ public void onSdlEnabled(Context context, Intent intent) {
1618 DebugTool .logInfo (TAG , "SDL Enabled" );
1719 intent .setClass (context , SdlService .class );
1820
19- // SdlService needs to be foregrounded in Android O and above
20- // This will prevent apps in the background from crashing when they try to start SdlService
21- // Because Android O doesn't allow background apps to start background services
22- try {
21+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
22+ if (intent .getParcelableExtra (TransportConstants .PENDING_INTENT_EXTRA ) != null ) {
23+ PendingIntent pendingIntent = (PendingIntent ) intent .getParcelableExtra (TransportConstants .PENDING_INTENT_EXTRA );
24+ try {
25+ pendingIntent .send (context , 0 , intent );
26+ } catch (PendingIntent .CanceledException e ) {
27+ e .printStackTrace ();
28+ }
29+ }
30+ } else {
31+ // SdlService needs to be foregrounded in Android O and above
32+ // This will prevent apps in the background from crashing when they try to start SdlService
33+ // Because Android O doesn't allow background apps to start background services
2334 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
2435 context .startForegroundService (intent );
2536 } else {
2637 context .startService (intent );
2738 }
28- } catch (Exception e ) {
29- DebugTool .logError ("RHENIGAN" , "Failed to start SdlService!" );
3039 }
3140 }
3241
0 commit comments