callkeep: backToForeground() does not work when app is closed on Android

First of all: This is a very nice library! I am using callkeep to display an incoming call notification when a message is received via firebase_messaging in onBackgroundMessage. When the user answers the incoming call I call backToForeground() and endCall() to just open the app when answering the call. This works pretty good when the app is running and in the background.

But when the app is closed and a message is received it shows the incoming call notification but when you click on answer, it doesn’t launch the app.

I think this is a critical feature for such use case since it can’t be guaranteed that the app is alive. I don’t know how easy it is to extend backToForeground() so it handles this case properly or if this is even possible at all.

I have yet to test the behavior on iOS if it launches the app by default because backToForeground is not implemented for iOS according to the source code of callkeep.

If you know an alternative solution, please let me know.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 29 (2 by maintainers)

Most upvoted comments

@ghenry I did a test and can wake up the app to the foreground. The logic code you used in the background can be moved to the app after startup, so there is no need to perform registration in the background.

Hello i have the same problem it cant ork in android 10, _callKeep.backToForeground(),seems not working on android 10 but in android 9 works

@jfaltis @ghenry @MaheshPeri19 @ahmedJD @payam-zahedi

fixed https://github.com/flutter-webrtc/callkeep/commit/b09080e5ed1e0fde09b64c006a3648f818240986

you can use it like this:

Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
  print('backgroundMessage: message => ${message.toString()}');
  Map<dynamic, dynamic> payload = message['data'] as Map<dynamic, dynamic>;
  String callerId = payload['caller_id'] as String;
  String callerName = payload['caller_name'] as String;

  bool appIsOpened = await _callKeep.backToForeground();
  if (appIsOpened) {
    print('APP is opened, use callkeep display incoming call now.');
    await displayIncomingCall(callerId, callerName);
  } else {
    print('APP is closed, wake it up and use callkeep to display incoming calls.');
  }
}

@jfaltis sure, I will test it on iOS and let you know