I'm a native Android/iOS dev new to ionic capacitor and javascript in general. I'm trying to send data from Android's OnNewIntent callback to the ionic-react project I'm working on. I'm doing this in the native MainActivity.java that extends BridgeActivity:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
getBridge().triggerDocumentJSEvent("MyEvent","blah");
}
And in my App.tsx file, I have something like this:
const App: React.FC = () => {
const onMyEvent = (input: string): void => {
console.log('event received: ${input}');
};
useEffect(() => {
document.addEventListener('MyEvent', () => {
console.log('MyEvent document');
onMyEvent(it.name);
});
window.addEventListener('MyEvent', () => {
console.log('MyEvent window');
onMyEvent(it.name);
});
}, []);
but I can't for the life of me get a message through from the native Activity to the App.tsx file. I've tried delaying the trigger for up to 15 seconds after the Activity is resumed to make sure everybody is instantiated, but I still never see indication that the message has been received. Is there an easy way to communicate from the native layer to the capacitor layer that I'm missing? Is it that these early Android lifecycle events happen before the ionic listeners have a chance to register? Just trying to send startup data that only the native side knows to the ionic side before rendering the first screen.
Thanks! Scott