From b89cc59b993dba0cdf4f1d6b8274085a20d48916 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 30 Jan 2023 20:22:54 -0500 Subject: [PATCH] Do not redirect to activity if not yet existing --- .../wazo/callkeep/VoiceConnectionService.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java index b513ce93..95756345 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java @@ -307,21 +307,24 @@ private void startForegroundService() { assert manager != null; manager.createNotificationChannel(chan); - Activity currentActivity = RNCallKeepModule.instance.getCurrentReactActivity(); - Intent notificationIntent = new Intent(this, currentActivity.getClass()); - notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); - - final int flag = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT; - - PendingIntent pendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, notificationIntent, flag); - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); notificationBuilder.setOngoing(true) .setContentTitle(foregroundSettings.getString("notificationTitle")) - .setContentIntent(pendingIntent) .setPriority(NotificationManager.IMPORTANCE_MIN) .setCategory(Notification.CATEGORY_SERVICE); + Activity currentActivity = RNCallKeepModule.instance.getCurrentReactActivity(); + if (currentActivity != null) { + Intent notificationIntent = new Intent(this, currentActivity.getClass()); + notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + + final int flag = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT; + + PendingIntent pendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, notificationIntent, flag); + + notificationBuilder.setContentIntent(pendingIntent); + } + if (foregroundSettings.hasKey("notificationIcon")) { Context context = this.getApplicationContext(); Resources res = context.getResources();