CallDetector.js
import CallDetectorManager from 'react-native-call-detection';
import CallLogs from 'react-native-call-log';
import { Linking } from 'react-native';
const detectCalls = () => {
console.log("Call detection started ::: ");
const callDetector = new CallDetectorManager(
(event, phoneNumber) => {
console.log("Event :: ", event);
if (event === 'Disconnected') {
//tried to open my app with deepLink
//This part is not opening my app from the background
Linking.openURL('myApp://call_add_edit').catch(err => console.error('Failed to open deep link:', err));
console.log('Call disconnected with number: ', phoneNumber);
},
true, // if you want to read the phone number of the incoming call [ANDROID], otherwise false
() => {
},
{
title: 'Phone State Permission',
message:
'This app needs access to your phone state in order to react and/or to adapt to incoming calls.',
}
);
return () => {
console.log("Calldetector desposed")
callDetector && callDetector.dispose();
};
}
export default detectCalls;
BackGroundTask
import BackgroundService from 'react-native-background-actions';
import BackgroundJob from 'react-native-background-actions';
import detectCalls from './CallDetector';
const sleep = time => new Promise(resolve => setTimeout(() => resolve(), time));
class BService {
constructor() {
this.Options = {
taskName: 'Demo',
taskTitle: 'Demo Running',
taskDesc: 'Demo',
taskIcon: {
name: 'ic_launcher',
type: 'mipmap',
},
color: '#ff00ff',
parameters: {
delay: 5000,
},
actions: '["Exit"]'
};
}
async VeryIntensiveTask(taskDataArguments) {
const { delay } = taskDataArguments;
await new Promise(async (resolve) => {
//Initiated background detection
detectCalls();
var i = 0;
for (let i = 0; BackgroundJob.isRunning(); i++) {
message: "Success DOOD " + i
// })
console.log("Background task is running ")
await sleep(delay);
}
});
}
Start() {
BackgroundService.start(this.VeryIntensiveTask, this.Options);
}
Stop() {
console.log("BackgroundService over ")
BackgroundService.stop();
}
isBackGroundRunning() {
return BackgroundService.isRunning();
}
}
const BackgroudService = new BService();
export default BackgroudService;
Problem:
When the app is in the background, the Linking.openURL(‘myApp://call_add_edit’) does not open the app or navigate to the specific screen.
However, it works perfectly when the app is in the foreground.
What I’ve Tried:
Ensuring that deep linking is set up correctly, which works in the foreground.
Using react-native-background-actions to run the call detection logic in the background.
Additional Information:
Package name: com.myApp
Deep link URL scheme: myApp://
Target screen: call_add_edit
1–> I’ve tried to implement the native libraries but it’s the same as before, it’ll work on foreground but not on background.
2–>I’ve tried by editing the package’s native code of react-native-call-detection and tried to open app directly from their by passing new Intent. but still it’s the same ? foreground : background.
Question:
How can I properly open my React Native app from the background and navigate to the call_add_edit screen using deep linking when a call is detected? Is there a specific approach or additional configuration required to achieve this?
or it’s possible that the way i’m doing it is also a wrong way but please share the another solution then Thanks!!
i’m so cooked!!!!