-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Receiving Events in the Background on Android #21
Comments
Hi @hsandhu, thanks for your message! This is normal behavior because when app is in background, code is executed independently of React context. When you are calling handleBackgroundState, But you can still listen to import messaging from '@react-native-firebase/messaging';
import { AppRegistry, Platform } from 'react-native';
import RNCallKeep from 'react-native-callkeep';
import {
RNTwilioPhone,
TwilioPhone,
twilioPhoneEmitter,
} from 'react-native-twilio-phone';
import { name as appName } from './app.json';
import { App } from './src/App';
function handleBackgroundState() {
if (Platform.OS !== 'android') {
return;
}
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
if (!remoteMessage.data) {
return;
}
RNCallKeep.registerPhoneAccount();
RNCallKeep.registerAndroidEvents();
RNCallKeep.setAvailable(true);
RNTwilioPhone.listenTwilioPhone(); // Listen to events after this line because listeners are removed here
RNTwilioPhone.listenCallKeep();
// Here you can listen to events and do what you want
twilioPhoneEmitter.addListener('CallConnected', (data) => {
console.log(data);
})
TwilioPhone.handleMessage(remoteMessage.data);
});
}
handleBackgroundState();
AppRegistry.registerComponent(appName, () => App); |
@MrHertal this is really helpful and makes sense, thank you! |
Thanks so much for your great library @MrHertal!
Running on Android 11 with Firebase Messaging configured, I can receive FCM notifications in the background from an incoming call and answer this call as well. I see the following message on logcat as the call is received:
D/TwilioPhone: Call did connect
However, this event is not received in the event listener in my App.tsx file (I've defined the listeners as you have in your example project). The events are received as expected in App.tsx if the incoming call is initialed while the app is in the foreground. Any thoughts as to why this event is not sent back through the React context and to the JS listener while the app is in the background?
The text was updated successfully, but these errors were encountered: