flutter: FlutterFcmService - Fatal: failed to find callback

Viewed 3336

I want to use fcm on my flutter app so after creating firebase console and installed some dependancies in my gradle like this:

build.gradle: Project

dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.3.3'
}

build.gradle: App

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
...
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics:17.5.0'
    implementation 'com.google.firebase:firebase-messaging:20.2.4'
}

And create a Java Application class:

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

public class Application extends FlutterApplication implements PluginRegistrantCallback {
    @Override
    public void onCreate() {
        super.onCreate();
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry registry) {
        FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
    }
}

And add this app class and intent-filter in manifest:

<application
    android:name=".Application"
    android:label="sian_mobile"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
    ...
                <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
            <action android:name="FLUTTER_NOTIFICATION_CLICK" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

And install firebase_messaging: ^7.0.0 in pubspect

I write this simple FirebaseMessaging code:

  FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  @override
  void initState() {
    super.initState();

    _firebaseMessaging.configure(
      onMessage: (message) async {
        print("-------> $message");
      },
      onResume: (message) async {
        print("-------> $message");
      },
      onLaunch: (message) async {},
    );
  }

When i run application and app is on forground i push notification from console to app. in vscode console i got this errors:

Installing build/app/outputs/flutter-apk/app.apk...
E/FlutterFcmService(11005): Fatal: failed to find callback
Connecting to VM Service at ws://127.0.0.1:41113/PSCQfaDH4oA=/ws
D/EGL_emulation(11005): eglMakeCurrent: 0xe83ba420: ver 2 0 (tinfo 0xc80dd6e0)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->size()I (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->get(I)I (greylist, reflection, allowed)
W/.ian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (greylist, reflection, allowed)
I/flutter (11005): -------> {notification: {title: test title, body: Test notification text}, data: {}}
1 Answers

It looks like the push message was still received when the app is in the foreground. The issue was likely caused by having no handlers for the push message while the app is in the background. I suggest going through this guide to set up a background message handler.

Related