flutter_callkit_incoming: I can`t accept call when app terminated

Hi. My app is working on foreground and background. When app is terminated state or not running, I see the incoming call notification but when I tap the accept button the app starts but does not go to the call screen

Debug consule : Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter_callkit_incoming_events. Response ID: 21

Event Code :

    FlutterCallkitIncoming.onEvent.listen((event) async {
      switch (event!.event) {
        case Event.ACTION_CALL_INCOMING:
          print(event.body['extra']['roomID']);
          break;
        case Event.ACTION_CALL_START:

          // TODO: started an outgoing call
          // TODO: show screen calling in Flutter
          break;
        case Event.ACTION_CALL_ACCEPT:
          navigatorKey.currentState?.push(
            MaterialPageRoute(
              builder: (context) =>
                  CallPage(callID: event.body['extra']['roomID']),
            ),
          );
          break;
        case Event.ACTION_CALL_DECLINE:
          // TODO: declined an incoming call
          break;
        case Event.ACTION_CALL_ENDED:
          // TODO: ended an incoming/outgoing call
          break;
        case Event.ACTION_CALL_TIMEOUT:
          // TODO: missed an incoming call
          break;
        case Event.ACTION_CALL_CALLBACK:
          // TODO: only Android - click action `Call back` from missed call notification
          break;
        case Event.ACTION_CALL_TOGGLE_HOLD:
          // TODO: only iOS
          break;
        case Event.ACTION_CALL_TOGGLE_MUTE:
          // TODO: only iOS
          break;
        case Event.ACTION_CALL_TOGGLE_DMTF:
          // TODO: only iOS
          break;
        case Event.ACTION_CALL_TOGGLE_GROUP:
          // TODO: only iOS
          break;
        case Event.ACTION_CALL_TOGGLE_AUDIO_SESSION:
          // TODO: only iOS
          break;
        case Event.ACTION_DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP:
          // TODO: Handle this case.
          break;
        case Event.ACTION_CALL_CUSTOM:
          // TODO: Handle this case.
          break;
      }
    });

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 16 (1 by maintainers)

Most upvoted comments

Have you solved this issue?

Yes, I solved it. First, tap the accept button of the terminated app. After opening the app, I check the active calls and if there is an active call, I decode it to json and go to the call screen

It works for me @Mfolio. thank you so much.

I still receive a duplicated call on the Android, when I pick up the call in the first 1-2 seconds. Do you have any idea to fix the duplication?

Have you solved this issue?

Yes, I solved it. First, tap the accept button of the terminated app. After opening the app, I check the active calls and if there is an active call, I decode it to json and go to the call screen

@Mfolio thanks for sharing, my issue is activeCalls() always return the last call info, How do you define that opening the app is from calling accept?

Just endActiveCalls every hangup

@Mfolio Have you solved this?

Same issue here, it only happens to Android/Huawei when terminated,

@firgia @erolyildiz33 Try

@pragma(‘vm:entry-point’) Future _messagingBackgroundHandler(RemoteMessage message) async { // your code here }

@booooohdan suggests using @pragma('vm:entry-point'), it seems that it doesn’t work for me because I am using OneSignal, not Firebase. OneSignal do not have a so-called backgroundHandler function, so a custom NotificationServiceExtension is needed to intercept the notification and show the call dialog.

Everything was working perfectly fine before, but now I’m not sure what happened and it’s not working again.

iOS Android Huawei
Terminated
Foreground
Background

I am currently using:

flutter: 3.7.8
flutter_callkit_incoming: ^1.0.3+3
onesignal_flutter: ^3.5.1

So the issue for me is that I use the showIncomingNotification function in native android (Kotlin) whenever a “call” notification is received as such:

// in my NotificationServiceExtension
val callkit = FlutterCallkitIncomingPlugin.getInstance()

callkit.showIncomingNotification(data)

It works when the app is in foreground/background, but when the app is terminated the call dialog is not shown. So I assumed there’s something to do with the context being null. So I “fix” it by manually creating the intent and passing the context as such:

// the context is from my NotificationServiceExtension
override fun remoteNotificationReceived(context: Context, notificationReceivedEvent: OSNotificationReceivedEvent) {
    ...
    val intent = CallkitIncomingBroadcastReceiver.getIntentIncoming(context, data.toBundle())

    CallkitNotificationManager(context).showIncomingNotification(data.toBundle())

    context.sendBroadcast(intent)

    notificationReceivedEvent.complete(null)
    ...
}

So the above code will show the call dialog when the app is terminated, however when I tap on Decline or Accept, the FlutterCallkitIncoming.onEvent.listen is not working, it is not receiving any event.

Anyone can help? @hiennguyen92

I can confirm this code worked previously, but I do not know what changed, Flutter’s new version? Would be great to have an update about this.