Skip to content

Commit c1b2325

Browse files
authored
Merge pull request #659 from react-native-webrtc/check_activity
Do not redirect to activity if not yet existing
2 parents 74b1e7d + b89cc59 commit c1b2325

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

+12-9
Original file line numberDiff line numberDiff line change
@@ -307,21 +307,24 @@ private void startForegroundService() {
307307
assert manager != null;
308308
manager.createNotificationChannel(chan);
309309

310-
Activity currentActivity = RNCallKeepModule.instance.getCurrentReactActivity();
311-
Intent notificationIntent = new Intent(this, currentActivity.getClass());
312-
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
313-
314-
final int flag = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT;
315-
316-
PendingIntent pendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, notificationIntent, flag);
317-
318310
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
319311
notificationBuilder.setOngoing(true)
320312
.setContentTitle(foregroundSettings.getString("notificationTitle"))
321-
.setContentIntent(pendingIntent)
322313
.setPriority(NotificationManager.IMPORTANCE_MIN)
323314
.setCategory(Notification.CATEGORY_SERVICE);
324315

316+
Activity currentActivity = RNCallKeepModule.instance.getCurrentReactActivity();
317+
if (currentActivity != null) {
318+
Intent notificationIntent = new Intent(this, currentActivity.getClass());
319+
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
320+
321+
final int flag = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT;
322+
323+
PendingIntent pendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, notificationIntent, flag);
324+
325+
notificationBuilder.setContentIntent(pendingIntent);
326+
}
327+
325328
if (foregroundSettings.hasKey("notificationIcon")) {
326329
Context context = this.getApplicationContext();
327330
Resources res = context.getResources();

0 commit comments

Comments
 (0)