Skip to content
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

No task registered for key ReactNativeFirebaseMessagingHeadlessTask #1454

Closed
luigbren opened this issue May 22, 2020 · 4 comments
Closed

No task registered for key ReactNativeFirebaseMessagingHeadlessTask #1454

luigbren opened this issue May 22, 2020 · 4 comments

Comments

@luigbren
Copy link

Question:

Hello friends, I'm configuring the remote notifications with Firebase, when I receive a notification with the app closed! and I open the app I get that error in yellow (No task registered for key ReactNativeFirebaseMessagingHeadlessTask), if I have the app open and I get a notification, everything is normal, I do not get any error...
my AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.mytestapp">
  
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-feature android:name="android.hardware.camera.front" android:required="false" />
    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
                           
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                android:value="YOUR NOTIFICATION CHANNEL NAME"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                    android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
        <!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                    android:value="true"/>
        <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->
        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <service
            android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>          
        
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter android:label="@string/app_name">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="app"
                  android:host="myapp" 
                  android:pathPrefix="/" />                  
            <data android:scheme="http"
                  android:host="myapp.com" 
                  android:pathPrefix="/" />           
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>
</manifest>

my App.js TEST

import React, { Component } from 'react';
import { View, Text, Button, PushNotification } from 'react-native';
import RNPushNotification from 'react-native-push-notification';

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }

  getNotifications = () => {
    RNPushNotification.localNotification({
      largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
      smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
      bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
      /* iOS and Android properties */
      title: "My Notification Title", // (optional)
      message: "My Notification Message", // (required)
      playSound: true, // (optional) default: true
    });
  }

  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text> App </Text>
        <Button title={"Get notifications"}
          onPress={this.getNotifications}
        />
      </View>
    );
  }
}

RNPushNotification.configure({
  // (optional) Called when Token is generated (iOS and Android)
  onRegister: function (token) {
    console.log("TOKEN:", token);
  },
  // (required) Called when a remote is received or opened, or local notification is opened
  onNotification: function (notification) {
    console.log("NOTIFICATION:", notification);
  },
});
@luigbren
Copy link
Author

ready!!. I solved the problem, what happens is that in the steps described here, said, install Firebase correctly, I installed the Firebase along with the component @react-native-firebase/messaging, that's why I gave the error "No task registered for key ReactNativeFirebaseMessagingHeadlessTask", and I uninstall the package "@react-native-firebase/messaging" and now if it works well remote notifications

@LightningNemesis
Copy link

@luigbren Were you able to receive the notification response for the notification received when the app was in the quit state?

@FelipeCararo
Copy link

I solved it as follows:


// index.js
import { AppRegistry, Alert } from 'react-native';
import messaging from '@react-native-firebase/messaging';

import App from './App';
import { name as appName } from './app.json';

messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
});

AppRegistry.registerComponent(appName, () => App);


This is because we have to validate when the push message arrives in the background in the app

@aqeelkhokhar
Copy link

I solved this by adding:

messaging().onMessage(onMessageReceived);
messaging().setBackgroundMessageHandler(onMessageReceived);

in index.js instead of App.js and use react-native-notify library to show notification locally.
this is the complete code of my index.js for Firebase notification configuration.

import notifee, {AndroidImportance, EventType} from '@notifee/react-native';
import messaging from '@react-native-firebase/messaging';

async function onMessageReceived(message) {
const channelId = await notifee.createChannel({
id: 'important',
name: 'Important Notifications',
importance: AndroidImportance.HIGH,
});
console.log('message received', JSON.stringify(message, null, 2));
try {
notifee.displayNotification({
title: message.notification.title,
body: message.notification.body,
android: {
channelId,
importance: AndroidImportance.HIGH,
},
});
} catch (e) {
console.log('error ....... push notification', e);
}
}

messaging().onMessage(onMessageReceived);
messaging().setBackgroundMessageHandler(onMessageReceived);

AppRegistry.registerComponent(appName, () => App);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants