1

When the application is closed my Android doesn't receive push notifications from Firebase, but if I open the app, everything works. Here is my MainActivity:

package com.imperio.app

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

And my Flutter configure:

void configure() {
    _firebaseMessaging.requestNotificationPermissions();

    _firebaseMessaging.configure(
      onLaunch: (params) {
        _bloc.onEventChanged(DispatchLaunch(params));
        return null;
      }, 
      onMessage: (params) {
        _bloc.onEventChanged(DispatchMessage(params));
        return null;
      }, 
      onResume: (params) {
        _bloc.onEventChanged(DispatchLaunch(params));
        return null;
      }
    );  
  }

When the application is open, I am receiving notifications normally. I see some people changing de MainActivity, but after embedded v2, Google documentation says nothing about it.

I added notification clicked in Android Manifest:

  <intent-filter>
      <action android:name="FLUTTER_NOTIFICATION_CLICK" />
      <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>

The problem is happening in Android 10, I tested in a Android 8 device and it works.

1 Answers1

1

in flutters firebase messaging documetation you have to add

 <intent-filter>
  <action android:name="FLUTTER_NOTIFICATION_CLICK" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

inside tag of mainfest.xml

and add Application.java and paste this code

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.FlutterFirebaseMessagingService;

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

  @Override
  public void registerWith(PluginRegistry registry) {
  GeneratedPluginRegistrant.registerWith(registry);
   }
  }

Set name property of application in AndroidManifest.xml. This is typically found in /android/app/src/main/.

<application android:name=".Application" ...>

you can get full documentation in https://pub.dev/packages/firebase_messaging

Biruk Telelew
  • 1,161
  • 7
  • 13
  • I had this erros: types using Application java: PluginRegistry cannot be converted to FlutterEngine GeneratedPluginRegistrant.registerWith(registry); ^ – Filippe Oliveira Da Silva Rodr Nov 26 '20 at 08:25
  • https://stackoverflow.com/questions/59446933/pluginregistry-cannot-be-converted-to-flutterengine check this link – Biruk Telelew Nov 26 '20 at 09:50
  • Now this error (I changed to FirebaseMessagingPlugin.registerWith instead of GeneratedPluginRegistrant): Unable to instantiate activity ComponentInfo{com.imperio.app/com.imperio.app.Application}: java.lang.ClassCastException: com.imperio.app.Application cannot be cast to android.app.Activity – Filippe Oliveira Da Silva Rodr Nov 26 '20 at 10:24
  • you should do that in Applications.java not in MainActivity.java and follow https://pub.dev/packages/firebase_messaging package step by step – Biruk Telelew Nov 26 '20 at 11:39
  • For sure, but my application is not receiving normal notifications with the application terminated. This configurations is for handle background notifications, with the application open. I tried to do like the documentation is saying about background notifications, but also not worked. – Filippe Oliveira Da Silva Rodr Nov 26 '20 at 11:46
  • i think its a problem with channel check this answer https://stackoverflow.com/questions/61943309/normal-push-notifications-appear-silently-or-not-at-all-when-the-flutter-app-is – Biruk Telelew Nov 26 '20 at 11:55
  • I managed to find out one more thing, on Android 8 it's working perfectly. However on Android 10 have the reported problem. – Filippe Oliveira Da Silva Rodr Nov 26 '20 at 18:54