Skip to content

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

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
lulupointu opened this issue Nov 12, 2020 · 5 comments
Labels
Needs Attention This issue needs maintainer attention. type: bug Something isn't working

Comments

@lulupointu
Copy link

lulupointu commented Nov 12, 2020

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

@lulupointu lulupointu added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Nov 12, 2020
@lulupointu
Copy link
Author

Change to channel master, flutter v1.24.0-8.0.pre.208. The issue is still there (on emulator and on real device).

@markusaksli-nc
Copy link
Contributor

Hi @lulupointu
I see there's an open issue addressing the case you described #2603.
Please follow up on that issue, I'm closing the current one as a duplicate.
If you disagree, please write in the comments and I will reopen it.
Thank you

@lulupointu
Copy link
Author

I agree that the issue is quite the same however there are 2 main differences:

  • I have no issue on IOS when I set it up
  • I am working with firebase_messaging 8.0.0-dev.8

If you think the issue is still too similar too reopen these thread, should I rewrite my issue in #2603?

@markusaksli-nc
Copy link
Contributor

#2603 is still open and there is no mention of a fix yet so I would expect it to also appear on 8.0.0-dev.8. This also seems to primarily be an Android issue, I'm seeing the exact same as you on Android with dev.8.

You can comment on #2603 to track the fact that this reproduces in 8.0.0-dev.8.

@lulupointu
Copy link
Author

Ok I will thanks

@firebase firebase locked and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Attention This issue needs maintainer attention. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants