1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Show incoming call notification when the app is terminated in flutter app

Discussão em 'Mobile' iniciado por Stack, Outubro 15, 2024 às 07:23.

  1. Stack

    Stack Membro Participativo

    I'm using Agora to implement a video call in my application, and I'm using this flutter_callkit_incoming to show incoming calls to the user.

    My flow is: when a call comes, it gets a notification from FCM and shows the Flutter incoming call kit notification. The flow works absolutely fine when the app is in the foreground and in the background (not terminated from the app switcher).

    When the app is terminated, FCM sends the notification for the call, but it is unable to trigger the call kit to initiate the incoming call. I need to trigger the call kit when the app is terminated.

    Is there any way to do it?

    Has anyone faced similar issues and solved them?

    heres the FCM background Handler This works absolutely fine when the app is in the background but not terminated, but it can't trigger the CallKit when the app is terminated.

    @pragma('vm:entry-point')
    Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
    await Firebase.initializeApp();


    String docName = '';
    String docImage = '';
    String uuid = '';

    dev.log('Message !also contained a notification: ${message.notification}');

    if (message.data['type'] == 'call') {
    PermissionRequestHandler.requestCameraAndMicPermissionsForCalling();
    docName = message.data['doc_name'];
    docImage = message.data['doc_image'];
    uuid = message.data['uuid'];

    logger.d('docName: $docName');
    logger.d('docImage: $docImage');

    showCallkitIncoming(docName, docImage, uuid);
    }
    }


    the function to trigger the callkit

    Future<void> showCallkitIncoming(
    String docName, String docImage, String uuid) async {
    final params = CallKitParams(
    id: uuid,
    nameCaller: docName,
    appName: 'AppName',
    avatar: docImage,
    type: 0,
    textAccept: 'Accept',
    textDecline: 'Decline',
    duration: 30000,
    missedCallNotification: const NotificationParams(isShowCallback: false),
    android: const AndroidParams(
    backgroundColor: '#2E2727',
    isCustomNotification: true,
    isShowLogo: false,
    isShowFullLockedScreen: true,
    ringtonePath: 'system_ringtone_default',
    ),
    ios: const IOSParams(
    iconName: 'Getfit',
    supportsVideo: false,
    audioSessionMode: 'default',
    audioSessionActive: true,
    audioSessionPreferredSampleRate: 44100.0,
    audioSessionPreferredIOBufferDuration: 0.005,
    supportsDTMF: true,
    supportsHolding: false,
    supportsGrouping: false,
    supportsUngrouping: false,
    ringtonePath: 'system_ringtone_default',
    ));

    await FlutterCallkitIncoming.showCallkitIncoming(params);
    }


    this is the error log when app is terminated and a call notification arrived from FCM. It didn't trigger the callkit incoming call notification rather logging this

    I/flutter (21552): FlutterFire Messaging: An error occurred in your background messaging handler:
    I/flutter (21552): PlatformException(java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly., Exception, Cause: null, Stacktrace: java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.
    I/flutter (21552): at io.flutter.plugins.firebase.core.i.v(Unknown Source:12)
    I/flutter (21552): at io.flutter.plugins.firebase.core.i.l(Unknown Source:0)
    I/flutter (21552): at io.flutter.plugins.firebase.core.b.run(Unknown Source:4)
    I/flutter (21552): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    I/flutter (21552): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
    I/flutter (21552): at java.lang.Thread.run(Thread.java:1012)
    I/flutter (21552): , null)

    Continue reading...

Compartilhe esta Página