5

I am trying to receive push notifications on ANDROID from the Firebase console when the app is terminated but I get nothing (I have onResume, onMessage and onLaunch callback listeners but I don’t even want to handle them in the app yet) I’d just like to get them to show In the tray or lock screen. Is there some Android configuration required?

2

2 Answers 2

6

first answer, I hope will be good.

As you can see here notifications are handled with onBackgroundMessage even if the app is terminated. Maybe your problem is that you are not sending a Notification but a "Data only" message. In that case you have to set the field "priority": "high"

Also, with the latest release of Flutter and firebase_messaging the methods onResume, onMessage and onLaunch are deprecated. You should substitute them with onMessage, onMessageOpened, onBackground, but you can find definitely more info with the official documentation

Sign up to request clarification or add additional context in comments.

Comments

0

Just an addition to @samUser1 answer. When app is terminated this code will handle events.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

And outside main function parse it. The example below uses AwesomeNotifications package. https://github.com/rafaelsetragni/awesome_notifications/blob/master/example/lib/main.dart

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();

  final res = await AwesomeNotifications().createNotification(
    content: NotificationContent(
      id: Random().nextInt(1000000),
      channelKey: 'channel_name',
      title: 'Hello!',
      body: 'World!',
      notificationLayout: NotificationLayout.Default,
    ),
  );
} 

1 Comment

with this configuration on the iOS side the whole main function is running whenever any data only notification is sent with app is on killed mode. This is causing side effects as runApp is running. Any way in which we can run only the high level function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.