flutter-webrtc / callkeep

iOS CallKit and Android ConnectionService for Flutter
MIT License
133 stars 147 forks source link

"Activity doesn't exist" #90

Closed Rob-Mat94 closed 3 years ago

Rob-Mat94 commented 3 years ago

Hi, I'm trying to receive call in background, so i follow the example, i add all the permission, etc ... I'm testing with FCM online tester. When i received the push notification, i'm trying to call "displayIncomingCall" but i got the following error : "Activity doesn't exist". Here is the log :

I/flutter (26016): Handling a background message: 0:1626366993137601%dc8262c0dc8262c0 I/flutter (26016): backgroundMessage: displayIncomingCall D/RNCK:VoiceConnectionService(26016): setAvailable: false D/RNCK:VoiceConnectionService(26016): setAvailable: true D/FLT:CallKeepModule(26016): backToForeground, app isOpened ?false

What can i have to add in android folder or dart code in order to work ... ?

AntonyLeons commented 3 years ago

Hi @Rob-Mat94,

I've opened a pull request with an updated example and instrustions. Could you test that and see if you get the same result. See #91

RobotMaths commented 3 years ago

Hi, thanks for your reply ! I will test that tomorrow. This error happens when the app is in background (Android) or terminate state. I didn't know if it was normal. Did you also fix the iOS crash in background ? I see many people which have this problem.

AntonyLeons commented 3 years ago

Hi, thanks for your reply ! I will test that tomorrow. This error happens when the app is in background (Android) or terminate state. I didn't know if it was normal. Did you also fix the iOS crash in background ? I see many people which have this problem.

All the firebase message callers have been refactored to support the newer libraries. When I tested iOS you can push the notification fine. The call will just fail to pick up as ios requires an audio stream for a call to continue.

Also iOS apps will have to be installed for background tests and iOS doesn't allow debug apps to run without an xcode connection.

Rob-Mat94 commented 3 years ago

Hi @AntonyLeons, i tested your update and all worked well. backToForeground(); is working now. I will soon try to pair callkeep with a webrtc call from 'flutter dart_sip_ua' to be sure. I just have one remark, when i used await callKeep.answerIncomingCall(event.callUUID); in the callback function. It seems that the is a infinite loop. D/RNCK:VoiceConnection(16809): onAnswer called D/RNCK:VoiceConnection(16809): onAnswer executed 2 I/flutter (16809): [CallKeep] INFO: received event "CallKeepPerformAnswerCallAction" {callUUID: 608} I/flutter (16809): ANSWER 608 I/flutter (16809): ANSWER PRESSED 2 I/flutter (16809): [CallKeep] INFO: received event "CallKeepDidActivateAudioSession" {} D/RNCK:VoiceConnection(16809): onAnswer called D/RNCK:VoiceConnection(16809): onAnswer executed 2 I/flutter (16809): [CallKeep] INFO: received event "CallKeepPerformAnswerCallAction" {callUUID: 608} I/flutter (16809): ANSWER 608 I/flutter (16809): ANSWER PRESSED

etc, etc, ...

AntonyLeons commented 3 years ago

HI @Rob-Mat94

I believe i fixed this in a commit 2 days ago, i cant replicate it

Rob-Mat94 commented 3 years ago

I used your repository https://github.com/AntonyLeons/callkeep.git with your commit but, maybe i have to use _callKeep.startCall(event.callUUID!, callerId, callerName); i think like the example.

AntonyLeons commented 3 years ago

Hi @AntonyLeons, i tested your update and all worked well. backToForeground(); is working now. I will soon try to pair callkeep with a webrtc call from 'flutter dart_sip_ua' to be sure. I just have one remark, when i used await callKeep.answerIncomingCall(event.callUUID); in the callback function. It seems that the is a infinite loop. D/RNCK:VoiceConnection(16809): onAnswer called D/RNCK:VoiceConnection(16809): onAnswer executed 2 I/flutter (16809): [CallKeep] INFO: received event "CallKeepPerformAnswerCallAction" {callUUID: 608} I/flutter (16809): ANSWER 608 I/flutter (16809): ANSWER PRESSED 2 I/flutter (16809): [CallKeep] INFO: received event "CallKeepDidActivateAudioSession" {} D/RNCK:VoiceConnection(16809): onAnswer called D/RNCK:VoiceConnection(16809): onAnswer executed 2 I/flutter (16809): [CallKeep] INFO: received event "CallKeepPerformAnswerCallAction" {callUUID: 608} I/flutter (16809): ANSWER 608 I/flutter (16809): ANSWER PRESSED

` etc, etc, ... `

I'm trying to do the same thing.

if you have this commit fix recursive call bfdde71

it should have worked, let me know how you get on

RobotMaths commented 3 years ago

Hi, so like you suggest I follow your commit bfdde71. With Function(CallKeepPerformAnswerCallAction) answerAction = (event) async { // SIPController.controller.signalAnswer(); await callKeep.setCurrentCallActive('608'); }; And it's working, thanks !.

Note (if its useful) : The function answerIncomingCall() still be recursive and startCall() throw me a exception : java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference My callkeep functions are in top main.

Another things, there is a way to have the timer in callscreen ?

RobotMaths commented 3 years ago

Hi @AntonyLeons, so i finished with Android (great work !). Now I'm trying to do to the same things on iOS but I need your help :/. All my project is configured well (VoIP Certificates, background process enable, etc ...). On background state, I would like to display incoming call but an error that I don't understand fired on callkeep deployment.

Here the logs : `2021-07-27 14:31:37.003732+0200 Runner[6097:813092] flutter: HANDLING BACKGROUND message ! 2021-07-27 14:31:37.004961+0200 Runner[6097:812985] [CallKeep][setup] options = { appName = "smart_diese"; } 2021-07-27 14:31:37.018377+0200 Runner[6097:812985] [CallKeep][reportNewIncomingCall] uuidString = 608 2021-07-27 14:31:37.026888+0200 Runner[6097:812985]

2021-07-27 14:31:37.028818+0200 Runner[6097:813092] flutter: [CallKeep] INFO: received event "CallKeepPushKitToken" {token: eecec1f4f42a4fd46b644384e184c214936c7f807990e5f30afb0edd6000bab7} 2021-07-27 14:31:37.257273+0200 Runner[6097:813092] flutter: [CallKeep] INFO: received event "CallKeepDidDisplayIncomingCall" {handle: Portier 608, hasVideo: false, localizedCallerName: , payload: , callUUID: 608, fromPushKit: false, error: } 2021-07-27 14:31:37.299945+0200 Runner[6097:813079] [Default] Error requesting calls from host: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.callkit.callcontrollerhost" UserInfo={NSDebugDescription=connection to service named com.apple.callkit.callcontrollerhost} 2021-07-27 14:31:37.305135+0200 Runner[6097:812985] [CallKeep][providerDidReset] 2021-07-27 14:31:37.320371+0200 Runner[6097:813092] flutter: [CallKeep] INFO: received event "CallKeepProviderReset" {} 2021-07-27 14:31:41.306017+0200 Runner[6097:812985]

2021-07-27 14:31:41.306296+0200 Runner[6097:812985]

2021-07-27 14:31:41.308715+0200 Runner[6097:813092] flutter: [CallKeep] INFO: received event "CallKeepPushKitToken" {token: eecec1f4f42a4fd46b644384e184c214936c7f807990e5f30afb0edd6000bab7} 2021-07-27 14:31:41.309755+0200 Runner[6097:813092] flutter: [CallKeep] INFO: received event "CallKeepPushKitToken" {token: eecec1f4f42a4fd46b644384e184c214936c7f807990e5f30afb0edd6000bab7}`

I'm testing on an iPhone 6S (debug mod), with iOS 12. I keep the same background callback as Android :

`static Future firebaseMessagingBackgroundHandler( RemoteMessage message) async { await Firebase.initializeApp(); //SIPController.controller.register(listener); print("HANDLING BACKGROUND message !"); if (!callKeepStarted) { try { await callKeep.setup(CallKeepCallbacks.callSetup); callKeepStarted = true; } catch (e) { print(e); } } callKeep.on( CallKeepPerformAnswerCallAction(), CallKeepCallbacks.answerAction); callKeep.on(CallKeepPerformEndCallAction(), CallKeepCallbacks.endAction);

await callKeep.displayIncomingCall('608', 'Portier 608', hasVideo: false);
callKeep.backToForeground();

}`

cdg720 commented 3 years ago

I get the same error with the callKeep.setup using callkeep: ^0.3.1:

Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
  final callKeep = FlutterCallkeep();
  callKeep.setup(null, <String, dynamic>{
    'ios': {
      'appName': 'CallKeepDemo',
    },
    'android': {
      'alertTitle': 'Permissions required',
      'alertDescription':
      'This application needs to access your phone accounts',
      'cancelButton': 'Cancel',
      'okButton': 'ok',
      'additionalPermissions': <String>[],
      'foregroundService': {
        'channelId': 'com.company.my',
        'channelName': 'Foreground service for my app',
        'notificationTitle': 'My app is running on background',
        'notificationIcon': 'Path to the resource icon of the notification',
      },
    },
  });
}

@Rob-Mat94 did you pass permissions to the setup config or did you add them in the AndroidManifest.xml. Also could you share what permissions you added?