Skip to content

🐛 [firebase_messaging 8.0.0-dev.8] Android notifications are recieved silently. No "peek into view". #4105

Closed
@lulupointu

Description

@lulupointu

Bug report

Describe the bug
When the app is in "Background" or "Terminated" state, the notification is received silently. Meaning that the icon appears in the notification tray but the notification title and background is not shown.

no_notification_android

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a new flutter app
  2. Create a new firebase project
  3. Follow the instruction to add firebase_core and firebase_messaging from FlutterFire. Ignore the IOS part but do all the Android part.
  4. Launch the app on your Android phone or in an Android emulator
  5. Click on the home button to enter the "Background" state.
  6. Go to the firebase console to compose and send a notification
  7. See on your phone that the notification appears in the notification tray but not peaked into view.
Click to see the flutter app (main.dart)
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  runApp(MyApp());

  FirebaseMessaging messaging = FirebaseMessaging.instance;
  print(await messaging.getToken());

  FirebaseMessaging.onMessage.listen((RemoteMessage message) {
    print('Got a message whilst in the foreground!');
    print('Message data: ${message.data}');

    if (message.notification != null) {
      print('Message also contained a notification: ${message.notification}');
    }
  });

  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  // If you're going to use other Firebase services in the background, such as Firestore,
  // make sure you call `initializeApp` before using other Firebase services.
  await Firebase.initializeApp();

  print("Handling a background message: ${message.messageId}");
}



class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Title'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Additional context

Tested on:

  • Real phone (Huawei LDN-L21) on Android 8.0
  • Emulator (Pixel 2) on Android Android 7.1
  • Emulator (Pixel 3a) on Android 10
  • Emulator (Pixel 4) on Android 11

Flutter doctor

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.3, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[!] Android Studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.51.0)
[✓] Connected device (2 available)

! Doctor found issues in 1 category.

Flutter dependencies

Click To Expand
Flutter SDK 1.22.3
flutter_test_fcm 1.0.0+1

dependencies:
- cupertino_icons 1.0.0
- firebase_core 0.5.2 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_messaging 8.0.0-dev.8 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]

dev dependencies:
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- async 2.5.0-nullsafety.1 [collection]
- boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
- characters 1.1.0-nullsafety.3
- charcode 1.2.0-nullsafety.1
- clock 1.1.0-nullsafety.1
- collection 1.15.0-nullsafety.3
- fake_async 1.2.0-nullsafety.1 [clock collection]
- firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_messaging_platform_interface 1.0.0-dev.5 [flutter meta firebase_core plugin_platform_interface]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- js 0.6.2
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.3
- path 1.8.0-nullsafety.1
- plugin_platform_interface 1.0.3 [meta]
- quiver 2.1.5 [matcher meta]
- sky_engine 0.0.99
- source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
- stack_trace 1.10.0-nullsafety.1 [path]
- stream_channel 2.1.0-nullsafety.1 [async]
- string_scanner 1.1.0-nullsafety.1 [charcode source_span]
- term_glyph 1.2.0-nullsafety.1
- test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0-nullsafety.3 [collection]
- vector_math 2.1.0-nullsafety.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs AttentionThis issue needs maintainer attention.type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions