Skip to content

Commit

Permalink
Merge pull request #659 from react-native-webrtc/check_activity
Browse files Browse the repository at this point in the history
Do not redirect to activity if not yet existing
  • Loading branch information
manuquentin authored Jan 31, 2023
2 parents 74b1e7d + b89cc59 commit c1b2325
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c1b2325

Please sign in to comment.