Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28460

With react-native-firebase v6, app crashed when receive notification while in foreground

$
0
0

I try to get react-native-firebase v6 to work in my app. I use React Native 0.59.10.

I have installed react-native-firebase v6 according to the documentation. It didn't specify about adding service MyFirebaseMessagingService into the AndroidManifest.xml unlike in v5 so I didn't do it. Afterwards, the app didn't receive any notification while in foreground but did receive them while in background.

I tried to add MyFirebaseMessagingService into AndroidManifest.xml like so:

<service
    android:name=".java.MyFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

There was some sort of a progress. The app crashed immediately after I sent a notification from Firebase console. Hence, I knew the app was aware of incoming notification but somehow crashed.

Below is my code to import and initialize a listener.

import messaging from '@react-native-firebase/messaging';
import { Alert } from 'react-native';

// Initialize notifications
const init = () => {
    try {
        messaging().onMessage((message) => {
            Alert.alert('Received', JSON.stringify(message));
        });
    } catch (err) {
        Alert.alert('Error', err.message);
    }
};

In summary, I expect to receive a notification while the app is in foreground but nothing happens if I don't add MyFirebaseMessagingService to AndroidManifest.xml. If I add it, the app will crash on receiving notification.


Viewing all articles
Browse latest Browse all 28460

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>