Skip to content

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

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

Closed
tinhpt38 opened this issue Feb 25, 2020 · 13 comments
Closed
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: messaging Stale Issue with no recent activity type: question A question where further information is requested

Comments

@tinhpt38
Copy link

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?

@iapicca iapicca added the type: question A question where further information is requested label Feb 25, 2020
@iapicca
Copy link

iapicca commented Feb 25, 2020

Hi @tinhpt38
does this answer help?
Thank you

@iapicca iapicca added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Feb 25, 2020
@tinhpt38
Copy link
Author

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

@iapicca
Copy link

iapicca commented Feb 26, 2020

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

@iapicca iapicca added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Feb 26, 2020
@michaelcastro
Copy link

Same error!

@michaelcastro
Copy link

michaelcastro commented Feb 27, 2020

@iapicca
Copy link

iapicca commented Feb 28, 2020

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

@iapicca iapicca added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Feb 28, 2020
@TahaTesser
Copy link

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
Copy link

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
Copy link
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!

@TahaTesser TahaTesser reopened this Mar 30, 2020
@kirstywilliams kirstywilliams changed the title Firebase Cloud Messaging [firebase_cloud_messaging] Error when using backgroundMessageHander as per docs Apr 27, 2020
@kirstywilliams kirstywilliams added impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: messaging and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Apr 27, 2020
@kirstywilliams kirstywilliams changed the title [firebase_cloud_messaging] Error when using backgroundMessageHander as per docs [firebase_messaging] Error when using backgroundMessageHander as per docs Apr 27, 2020
@saravananmnm
Copy link

saravananmnm commented May 15, 2020

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
Copy link

saravananmnm commented May 15, 2020

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
Copy link

I solved this issue

#2777 (comment)

@Salakar Salakar added the Stale Issue with no recent activity label Apr 1, 2021
@russellwheatley
Copy link
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.

@firebase firebase locked and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: messaging Stale Issue with no recent activity type: question A question where further information is requested
Projects
None yet
Development

No branches or pull requests

10 participants