React-native-push-notification: No task registered for key ReactNativeFirebaseMessagingHeadlessTask

Created on 23 May 2020  路  2Comments  路  Source: zo0r/react-native-push-notification

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);
  },
});

Most helpful comment

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

All 2 comments

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NiuQiaoling picture NiuQiaoling  路  3Comments

selimonline picture selimonline  路  3Comments

sungjinoh picture sungjinoh  路  3Comments

nidzovito picture nidzovito  路  3Comments

nguyenvanphuc2203 picture nguyenvanphuc2203  路  3Comments