Skip to content

[firebase_messaging] Error when using backgroundMessageHander as per docs #2055

Closed
@tinhpt38

Description

@tinhpt38

Hi! I set up a firebase cloud messing for my flutter application.
I using backgoundMessageHandler and I implemented like that documentation but I take errors:

  1. If I do not implement backgroundMessagehandler when I push notification from the firebase console then my app crash.
  2. When I set up native code like that

Screen Shot 2020-02-25 at 10 34 18 AM

In the documentation then GeneratedPluginRegistrant.registerWith(registry); with input is PluginRegistry but in the native code (Kotlin) then input is FlutterEngine.
Screen Shot 2020-02-25 at 10 34 02 AM

And why?

Activity

iapicca

iapicca commented on Feb 25, 2020

@iapicca

Hi @tinhpt38
does this answer help?
Thank you

tinhpt38

tinhpt38 commented on Feb 26, 2020

@tinhpt38
Author

Hi @iapicca !
I tried it but not help! I will take the same error!
Thanks you!

iapicca

iapicca commented on Feb 26, 2020

@iapicca

Hi @tinhpt38
can you please provide your flutter doctor -v ,
your flutter run --verbose, your pubspec.yaml
and if possible an updated reproducible minimal code sample.
Thank you

added
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
and removed
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
on Feb 26, 2020
michaelcastro

michaelcastro commented on Feb 27, 2020

@michaelcastro

Same error!

iapicca

iapicca commented on Feb 28, 2020

@iapicca

Hi @tinhpt38
does @michaelcastro (thanks) solution works for you?
Thank you

added
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
and removed
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
on Feb 28, 2020
TahaTesser

TahaTesser commented on Mar 27, 2020

@TahaTesser

Hi @tinhpt38
Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore
reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any
more information for us; we will reopen it right away!
Thanks for your contribution.

LasseRosenow

LasseRosenow commented on Mar 27, 2020

@LasseRosenow

Excuse me? But didn't @tinhpt38 already give you all the information you need?

If you create a new flutter project and setup firebase_messaging background handling the way it's explained in the readme, you should get the same error as he got.

What more do you want? Many people including me face this issue and its very frustrating.

tinhpt38

tinhpt38 commented on Mar 28, 2020

@tinhpt38
Author

hi @lazylazyllama and @michaelcastro, for now, I still get an error when I using the background handle of firebase messing! I am going to waiting for any version upgrade to can fix it!

changed the title [-]Firebase Cloud Messaging [/-] [+][firebase_cloud_messaging] Error when using backgroundMessageHander as per docs[/+] on Apr 27, 2020
added
impact: customerA bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)
and removed
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
on Apr 27, 2020
changed the title [-][firebase_cloud_messaging] Error when using backgroundMessageHander as per docs[/-] [+][firebase_messaging] Error when using backgroundMessageHander as per docs[/+] on Apr 27, 2020
saravananmnm

saravananmnm commented on May 15, 2020

@saravananmnm
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationView extends StatefulWidget {
  @override
  NotificationState createState() {
    return NotificationState();
  }
}

class NotificationState extends State<NotificationView> {
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
  FirebaseMessaging firebaseMessaging = new FirebaseMessaging();

  @override
  void initState() {
    initialize();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }

  showNotification() async {
    var androidPlatformChannelSpecifies = new AndroidNotificationDetails(
      "i-eX Driver",
      "i-eX Driver",
      "Test",
      importance: Importance.Max,
      priority: Priority.High,
      color: Colors.blue,
      autoCancel: true,
      largeIcon: DrawableResourceAndroidBitmap('@mipmap/engineer'),
      icon: '@mipmap/engineer',
    );
    var iOSPlatformChannelSpecifics =
        new IOSNotificationDetails(presentAlert: true);
    var platformChannelSpecifics = new NotificationDetails(
        androidPlatformChannelSpecifies, iOSPlatformChannelSpecifics);
    String data = "what to do with notification hereafetr kkklk....";
    firebaseMessaging.configure(
      onLaunch: (Map<String, dynamic> msg) {
        print(" onLaunch called ${(msg)}");
      },
      onResume: (Map<String, dynamic> msg) {
        print(" onResume called ${(msg)}");
      },
      onMessage: (Map<String, dynamic> msg) async {
        print(" onMessage called ${msg}");
        String val = '';
        msg.entries.map((v) {
          if (v.key == 'data') {
            v.value.entries.map((s) {
              if (s.key == 'body') val = s.value;
            }).toList();
          }
        }).toList();
        print(" onMessage called ${(val)}");
        await flutterLocalNotificationsPlugin.show(
            0, 'i-eX Driver', val, platformChannelSpecifics);
      },
    );
  }

  Future onDidReceiveLocalNotification(
      int id, String title, String body, String payload) async {
    showDialog(
      context: context,
      builder: (BuildContext context) => new CupertinoAlertDialog(
        title: new Text(title),
        content: new Text(body),
        actions: [
          CupertinoDialogAction(
            isDefaultAction: true,
            child: new Text('Ok'),
            onPressed: () async {
              Navigator.of(context, rootNavigator: true).pop();
            },
          )
        ],
      ),
    );
  }

  void initialize() async {
    AndroidInitializationSettings android = new AndroidInitializationSettings(
        '@mipmap/engineer'); //@mipmap/ic_launcher
    IOSInitializationSettings ios = new IOSInitializationSettings(
        onDidReceiveLocalNotification: onDidReceiveLocalNotification);
    var initSettings = new InitializationSettings(android, ios);
    flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
    flutterLocalNotificationsPlugin.initialize(initSettings);
    firebaseMessaging.requestNotificationPermissions(
        const IosNotificationSettings(sound: true, alert: true, badge: true));
    firebaseMessaging.onIosSettingsRegistered
        .listen((IosNotificationSettings setting) {
      print('IOS Setting Registed');
    });
    await firebaseMessaging.onTokenRefresh.listen((token) {
      print('FCM : ${token}');
    });

    showNotification();
  }
}
saravananmnm

saravananmnm commented on May 15, 2020

@saravananmnm

try this code


import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;

public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {

    @Override
    public void onCreate() {
        super.onCreate();
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry registry) {
        // I've only had to add this line to make it work
        FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
    }
}

And Main activity

import android.os.Bundle;

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
  @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    GeneratedPluginRegistrant.registerWith(flutterEngine);
  }
}
naveenkumardot25

naveenkumardot25 commented on Sep 2, 2020

@naveenkumardot25

I solved this issue

#2777 (comment)

russellwheatley

russellwheatley commented on Apr 16, 2021

@russellwheatley
Member

Closing in favour of trying the latest messaging version which has been been heavily reworked, along with documentation, since this issue was raised: https://firebase.flutter.dev/docs/messaging/overviewIf you still have a problem please raise a new GitHub issue with up to date information and code snippets if possible. Thanks.

locked and limited conversation to collaborators on May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleIssue with no recent activityimpact: customerA bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)plugin: messagingtype: questionA question where further information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kirstywilliams@michaelcastro@Salakar@LasseRosenow@russellwheatley

        Issue actions

          [firebase_messaging] Error when using backgroundMessageHander as per docs · Issue #2055 · firebase/flutterfire