flutter-webrtc / callkeep

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

_ACTIVITY_DOES_NOT_EXIST, Activity doesn't exist, null, null #109

Closed ScottLee97 closed 3 years ago

ScottLee97 commented 3 years ago

I am having the below error

E/flutter (14667): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(E_ACTIVITY_DOES_NOT_EXIST, Activity doesn't exist, null, null) E/flutter (14667): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7) E/flutter (14667): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18) E/flutter (14667): E/flutter (14667): #2 FlutterCallkeep._checkPhoneAccountPermission (package:callkeep/src/api.dart:325:16) E/flutter (14667): E/flutter (14667): #3 FlutterCallkeep._setupAndroid (package:callkeep/src/api.dart:302:30) E/flutter (14667): E/flutter (14667): #4 FlutterCallkeep.setup (package:callkeep/src/api.dart:39:7) E/flutter (14667):

Below is my background message handler

Future<dynamic> myBackgroundMessageHandler(RemoteMessage? message) async {
  if (message == null) {
    return null;
  }
  print('backgroundMessage: message => ${message.toString()}');
  var payload = message.data;
  var callerId = payload['caller_id'] as String;
  var callerNmae = payload['caller_name'] as String;
  var uuid = payload['uuid'] as String;
  var hasVideo = payload['has_video'] == "true";

  final callUUID = uuid ?? Uuid().v4();
  _callKeep.on(CallKeepPerformAnswerCallAction(),
      (CallKeepPerformAnswerCallAction event) {
    print(
        'backgroundMessage: CallKeepPerformAnswerCallAction ${event.callUUID}');
    _callKeep.startCall(event.callUUID!, callerId, callerNmae);

    Timer(const Duration(seconds: 1), () {
      print(
          '[setCurrentCallActive] $callUUID, callerId: $callerId, callerName: $callerNmae');
      _callKeep.setCurrentCallActive(callUUID);
    });
    //_callKeep.endCall(event.callUUID);
  });

  _callKeep.on(CallKeepPerformEndCallAction(),
      (CallKeepPerformEndCallAction event) {
    print('backgroundMessage: CallKeepPerformEndCallAction ${event.callUUID}');
  });
  if (!_callKeepInited) {
    _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',
        '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',
        },
      },
    });
    _callKeepInited = true;
  }

  print('backgroundMessage: displayIncomingCall ($callerId)');
  _callKeep.displayIncomingCall(callUUID, callerId,
      localizedCallerName: callerNmae, hasVideo: hasVideo);
  _callKeep.backToForeground();
  /*
  if (message.containsKey('data')) {
    // Handle data message
    final dynamic data = message['data'];
  }
  if (message.containsKey('notification')) {
    // Handle notification message
    final dynamic notification = message['notification'];
    print('notification => ${notification.toString()}');
  }
  // Or do other work.
  */
  return null;
}

Below is my android manifest

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- The Agora SDK requires Bluetooth permissions in case users are using Bluetooth devices.-->
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->

    <!-- Permissions options for the `contacts` group -->
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

    <uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />

Does anyone know how to resolve this error? Thanks in advance!

efraespada commented 3 years ago

I'm not sure this is an error.

This exception appears to me when the app is closed and I invoke the setup method when there is no activity present.

Maybe I'm wrong, but the setup method can't work without the activity and it should not be called from the background handler of Firebase.

ScottLee97 commented 3 years ago

Thanks for the reply. I found out where was the issue. I had changed the name of the app and the calling accounts permission in the setting has to be changed too. Once I enabled the calling accounts permission, the error does not appear anymore.

Thanks!