I am working on a React Native Expo project where I need to handle incoming call notifications using expo-notifications, expo-task-manager, and react-native-callkeep. The goal is to display an incoming call screen even when the app is terminated (killed/closed). Here’s what I’ve implemented so far:
import { Component } from 'react';
import Routes from "./Navigations/Route";
import * as React from 'react';
import { registerRootComponent } from 'expo';
import { Provider } from 'react-redux';
import store from './store/store';
import * as TaskManager from "expo-task-manager";
import * as Notifications from "expo-notifications";
import CallKeep from 'react-native-callkeep';
const BACKGROUND_NOTIFICATION_TASK = "BACKGROUND-NOTIFICATION-TASK";
TaskManager.defineTask(
BACKGROUND_NOTIFICATION_TASK,
({ data, error, executionInfo }) => {
if (error) {
console.log("Error occurred:", error);
}
if (data) {
console.log("Data received:", data);
let res = JSON.parse(data.notification.data.body);
CallKeep.displayIncomingCall(res.uuid, "9999999999", res.instructorName, 'generic', true);
}
}
);
Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);
export default class App extends Component {
componentDidMount() {
// Any other initialization
}
render() {
return (
<Provider store={store}>
<Routes />
</Provider>
);
}
};
registerRootComponent(App);
The Problem:
This implementation works fine when the app is in the foreground or background. When a data-only notification is received, the background task is triggered, and CallKeep successfully displays the incoming call screen.
However, when the app is terminated (killed/closed), the background task is not triggered, and the incoming call screen does not appear. I am using expo-notifications, expo-task-manager, and react-native-callkeep.
How can I handle incoming calls and trigger CallKeep when the app is terminated (killed/closed)?
Any suggestions or workarounds to ensure expo-task manager or a similar service can handle background notifications when the app is not running?
I tested this in Android