2323import android .app .Notification ;
2424import android .app .NotificationChannel ;
2525import android .app .NotificationManager ;
26+ import android .content .res .Resources ;
2627import android .content .Intent ;
2728import android .content .Context ;
2829import android .content .ComponentName ;
@@ -216,6 +217,10 @@ private Connection makeOutgoingCall(ConnectionRequest request, String uuid, Bool
216217 }
217218
218219 private void startForegroundService () {
220+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
221+ // Foreground services not required before SDK 28
222+ return ;
223+ }
219224 if (_settings == null || !_settings .hasKey ("foregroundService" )) {
220225 Log .d (TAG , "Not creating foregroundService because not configured" );
221226 return ;
@@ -230,11 +235,19 @@ private void startForegroundService() {
230235 manager .createNotificationChannel (chan );
231236
232237 NotificationCompat .Builder notificationBuilder = new NotificationCompat .Builder (this , NOTIFICATION_CHANNEL_ID );
233- Notification notification = notificationBuilder .setOngoing (true )
234- .setContentTitle (foregroundSettings .getString ("notificationTitle" ))
235- .setPriority (NotificationManager .IMPORTANCE_MIN )
236- .setCategory (Notification .CATEGORY_SERVICE )
237- .build ();
238+ notificationBuilder .setOngoing (true )
239+ .setContentTitle (foregroundSettings .getString ("notificationTitle" ))
240+ .setPriority (NotificationManager .IMPORTANCE_MIN )
241+ .setCategory (Notification .CATEGORY_SERVICE );
242+
243+ if (foregroundSettings .hasKey ("icon" )) {
244+ Context context = this .getApplicationContext ();
245+ Resources res = context .getResources ();
246+ String smallIcon = foregroundSettings .getString ("icon" );
247+ notificationBuilder .setSmallIcon (res .getIdentifier (smallIcon , "mipmap" , context .getPackageName ()));
248+ }
249+
250+ Notification notification = notificationBuilder .build ();
238251 startForeground (FOREGROUND_SERVICE_TYPE_MICROPHONE , notification );
239252 }
240253
0 commit comments