react-native-callkeep: backToForeground not working

Bug report

  • [ ✓] I’ve checked the example to reproduce the issue.

  • Reproduced on:

  • [✓ ] Android

  • iOS

Description

backToForeground does not invoke the app when the app is in background or quit state

Steps to Reproduce

I have following code in index.js

const options = {
    ios: {
        appName: 'App Name',
        imageName: 'logo-trans'
    },
    android: {
        alertTitle: 'Permissions required',
        alertDescription: 'This application needs to access your phone accounts',
        cancelButton: 'Cancel',
        okButton: 'Ok',
    }
};
RNCallKeep.setup(options);

messaging().setBackgroundMessageHandler(async remoteMessage => {
    const { data } = remoteMessage;
    if ('voip' === data?.type) {
        RNCallKeep.backToForeground();
        RNCallKeep.displayIncomingCall(data.uuid, data.handle, data.callerName);
        return;
    }
});

displayIncomingCall is invoked but RNCallKeep.backToForeground() does not do anything

Versions

- Callkeep: 4.2.0
- React Native: 0.61
- Android: 10

Logs

Paste here

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Any update on this?

There seems to be a race condition if the app is already in the foreground when you answer the call.

Here is my understanding of what happens:

  1. The app is in the foreground
  2. It receives a call
  3. The call is accepted
  4. backToForeground() gets called – while the app is still in the foreground.
  5. The OS switches to the phone UI

This solutions is not elegant at all but worked for me:

RNCallKeep.addEventListener("answerCall", async ({ handle, callUUID, name }) => {
  for (var i = 0; i < 10; i++) {
    RNCallKeep.backToForeground()
  }
})

There seems to be a race condition if the app is already in the foreground when you answer the call.

Here is my understanding of what happens:

  1. The app is in the foreground
  2. It receives a call
  3. The call is accepted
  4. backToForeground() gets called – while the app is still in the foreground.
  5. The OS switches to the phone UI

This solutions is not elegant at all but worked for me:

RNCallKeep.addEventListener("answerCall", async ({ handle, callUUID, name }) => {
  for (var i = 0; i < 10; i++) {
    RNCallKeep.backToForeground()
  }
})

This worked for me

try to enable this permission

Settings app > Other permissions > Display pop-up windows while running in the background

this fixed in my case, Xiaomi 11 phone

Facing same issue and @glesperance’s workaround works.

I was already calling it in the answer call listener but didn’t work out.

I suppose we cannot call backToForeground before displayIncomingCall which I tried to do. Where I changed my approach mainly is to call backToForeground in answerCall event

Any pointer here is really appreciated. No solution is working for me until now.