Skip to content

Commit d7c65cc

Browse files
committed
Improve check on foreground service and add icon in settings
1 parent 6c81cab commit d7c65cc

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.app.Notification;
2424
import android.app.NotificationChannel;
2525
import android.app.NotificationManager;
26+
import android.content.res.Resources;
2627
import android.content.Intent;
2728
import android.content.Context;
2829
import 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

Comments
 (0)