Skip to content

Commit 188fc52

Browse files
committed
Allow foreground service notification to open the application
1 parent 1c850e4 commit 188fc52

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ private void registerPhoneAccount(Context appContext) {
968968
telecomManager.registerPhoneAccount(account);
969969
}
970970

971-
private void sendEventToJS(String eventName, @Nullable WritableMap params) {
971+
public void sendEventToJS(String eventName, @Nullable WritableMap params) {
972972
boolean isBoundToJS = this.reactContext.hasActiveCatalystInstance();
973973
Log.v(TAG, "[RNCallKeepModule] sendEventToJS, eventName: " + eventName + ", bound: " + isBoundToJS + ", hasListeners: " + hasListeners + " args : " + (params != null ? params.toString() : "null"));
974974

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import android.app.Notification;
2424
import android.app.NotificationChannel;
2525
import android.app.NotificationManager;
26+
import android.app.PendingIntent;
27+
import android.app.Activity;
2628
import android.content.res.Resources;
2729
import android.content.Intent;
2830
import android.content.Context;
@@ -82,6 +84,7 @@ public class VoiceConnectionService extends ConnectionService {
8284
private static ConnectionRequest currentConnectionRequest;
8385
private static PhoneAccountHandle phoneAccountHandle;
8486
private static String TAG = "RNCallKeep";
87+
private static int NOTIFICATION_ID = -4567;
8588

8689
// Delay events sent to RNCallKeepModule when there is no listener available
8790
private static List<Bundle> delayedEvents = new ArrayList<Bundle>();
@@ -304,9 +307,18 @@ private void startForegroundService() {
304307
assert manager != null;
305308
manager.createNotificationChannel(chan);
306309

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+
307318
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
308319
notificationBuilder.setOngoing(true)
309320
.setContentTitle(foregroundSettings.getString("notificationTitle"))
321+
.setContentIntent(pendingIntent)
310322
.setPriority(NotificationManager.IMPORTANCE_MIN)
311323
.setCategory(Notification.CATEGORY_SERVICE);
312324

0 commit comments

Comments
 (0)