react-native-callkeep icon indicating copy to clipboard operation
react-native-callkeep copied to clipboard

"createIncomingConnectionFailed" event is fired every time I show the incoming call ui in self managed mode

Open RamsayRomero opened this issue 2 years ago • 3 comments

I'm using self managed mode for android. I'm using react-native-firebase to listen for fcm messages and Notifee to register a foreground service and build notifications. Here's what I'm doing in my index.js:

RNCallKeep.setup({
  android: {
    alertTitle: 'Permissions required',
    alertDescription: 'This application needs to access your phone account',
    cancelButton: 'Cancel',
    okButton: 'Ok',
    selfManaged: true,
  },
});

// creates an android notification channel for incoming calls
notifee.createChannel({
  id: 'call',
  name: 'Incoming Call',
  importance: AndroidImportance.HIGH,
});

// creates a foreground service
notifee.registerForegroundService((notification) => {
  return new Promise(() => {
    notifee.onBackgroundEvent(async ({ type, detail }) => {
      // handle interactions with incoming call notification when app is in background
    });
    notifee.onForegroundEvent(async ({ type, detail }) => {
      // handle interactions with the incoming call notification when app is in foreground
    });
  });
});

// creates a headless js task to listen for background messages
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
  // If message is an incoming call
  RNCallKeep.displayIncomingCall();
});

In my app I have a useEffect which adds callkeep event listeners including:

RNCallKeep.addEventListener('showIncomingCallUi', ({ handle, callUUID, name }) => {
      notifee.displayNotification({
        id: callUUID,
        title: name || handle,
        body: 'Incoming call',
        android: {
          channelId: 'call',
          asForegroundService: true,
          category: AndroidCategory.CALL,
          fullScreenAction: { id: 'call' },
          actions: [
            { title: 'Decline', pressAction: { id: 'endCall' } },
            { title: 'Accept', pressAction: { id: 'answerCall' } },
          ],
          importance: AndroidImportance.HIGH,
        },
      });
    });

This builds a notification with full screen intent, high priority and associates it with a foreground service that I defined in my AndroidManifest.xml:

<service android:name="app.notifee.core.ForegroundService" android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE" android:foregroundServiceType="camera|microphone">
  <intent-filter>
    <action android:name="android.telecom.ConnectionService"/>
  </intent-filter>
</service>

When I receive an incoming call when my app is in the background state. My background message handler calls RNCallkeep.displayIncomingCall(), the 'showIncomingCallUi' event is fired, and I display the notification associated to the foreground service. The "createIncomingConnectionFailed" is then fired every time, which ends the call and the service. When the app is in the foreground state everything works. I have verified that my device has granted all permissions and I even added additional permissions to my AndroidManifest.xml:

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

I'll also add that I have not removed the callkeep foreground service from my AndroidManifest.xml. It's unclear from the docs whether I need to remove that service or not when using self managed mode and if so, what additional steps there are to take when removing the service. I tried a build where I removed the callkeep foreground service but got the error: PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission.

Any possible reasons why this may be occurring is appreciated.

RamsayRomero avatar Feb 14 '23 00:02 RamsayRomero

I had one similar issue because I wasn't calling the RNCK.endCall(uuid) after terminating the call.

mariouzae avatar Feb 24 '23 18:02 mariouzae

Hi @RamsayRomero , I think if you have your own connection service, you can remve connection service from react native callkeep.

huynextlevel avatar Dec 02 '23 07:12 huynextlevel