Skip to content
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

Android 12 not showing notification #1328

Closed
JavierConde opened this issue Oct 8, 2021 · 6 comments
Closed

Android 12 not showing notification #1328

JavierConde opened this issue Oct 8, 2021 · 6 comments

Comments

@JavierConde
Copy link

JavierConde commented Oct 8, 2021

Hi folks,

first, i read the other bugs here respect this problem, and see this could be resolve in v.9.0.0.

I updated my application to these versions:

firebase_core: ^1.7.0
firebase_messaging: ^10.0.8
flutter_local_notifications: ^9.0.0

I'm using flutter:
Flutter 2.5.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 3595343e20 (8 days ago) • 2021-09-30 12:58:18 -0700
Engine • revision 6ac856380f
Tools • Dart 2.14.3

In my manifest, i have this:

<application
        android:label="GeoTareas"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true"
        android:exported="true"
        >

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
          
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />

            <meta-data
                android:name="com.google.firebase.messaging.default_notification_channel_id"
                android:value="logictrack"/>

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>

i initialized the plugin in a service and try to display the notification like this:


import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class LocalNotificationService {
  static final FlutterLocalNotificationsPlugin _futterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
  static initialize(BuildContext context) async {
    final InitializationSettings initializationSettings = InitializationSettings(android: AndroidInitializationSettings("@mipmap/ic_launcher"));

    await _futterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: (String? payload) async {
      // Navigator.of(context).pushNamed(payload);
      print('payload: $payload');
    });
  }

  static void display(RemoteMessage message) async {
    try {
      final double dt = DateTime.now().millisecondsSinceEpoch / 1000;
      final int id = dt.toInt();

      final NotificationDetails notificationDetails = NotificationDetails(
        android: AndroidNotificationDetails(
          'logictrack',
          'High Importance Notifications',
          channelDescription: 'High Importance Notifications',
          priority: Priority.max,
          importance: Importance.max,
        ),
      );

      print(message.notification!.title);

      _futterLocalNotificationsPlugin.show(
        id,
        message.notification!.title,
        message.notification!.body,
        notificationDetails,
        // payload: message.data['item']
      );
    } on Exception catch (e) {
      print('Error display $e');
    }
  }
}

my gradle is configured:
compileSdkVersion 31
and
minSdkVersion 21
targetSdkVersion 31

before the update, this plugin was working well, popup the notif always, after the update, never more works, the push is received in the phone, i can configure the sound, etc and works fine, but the local notifcation never show ups.

Repeat, i read the other posts about this, search on internet and spend 2 days on this without any solution.

Could you guys try to help me?

thanks!

@MaikuB
Copy link
Owner

MaikuB commented Oct 8, 2021

Please provide a link to a minimal app that can reproduce the problem. Did you also try to run the example app in the repository to see if it could reproduce the problem. Both of these are mentioned in the bug report template, which is what should've been used for instances like this

Edit: note that there have been others using the changes back when 9.0.0 was in prerelease without issues as they needed to target Android 12. Asking you to take the steps I've mentioned above is to ensure you've tried to isolate the issue. This also includes you trying to use the plugin on its own

@JavierConde
Copy link
Author

Hello MaikuB, i cloned the repository and install the example in a phone A10 with Android 11. The first option, justo show in the taskbar the icon, but not sound and not show a desplegable windows from the top like before.
I try to do the same on a S21 with android 11 and is the same

@MaikuB
Copy link
Owner

MaikuB commented Oct 13, 2021

The first option, justo show in the taskbar the icon

This is expected behaviour for that example. If you are surprised that this is happening then you may need to familiarise yourself more with how notifications on Android work around setting importance and priority levels.

but not sound

You need to check your phone's settings then. This is working fine on my own devices. If there was an issue with sound that is to do with this plugin then this issue would be much more widely reported. I've seen issues reported where it turns out the person reporting a bug wasn't familiar with the settings of the devices they were using. This may be the case here as well. The volume setting for playing media is different for system sounds like ringtone and notifications

@JavierConde
Copy link
Author

ok, I try to test on other android devices.

Now, I'm using a MacOS to test the app on iOS and when do the init crash.

log] Null check operator used on a null value
[log] #0 FlutterLocalNotificationsPlugin.initialize
package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:129
#1 LocalNotificationService.initialize
package:geotareasmobile/…/firebase/local_notification_service.dart:12

this is too a config issue?

@MaikuB
Copy link
Owner

MaikuB commented Oct 13, 2021

Yes. If you want to report any bugs then fork the repository and use the example app as the means to provide a minimal way to reproduce any bugs.

Edit: if you haven't experienced this issue before then I would suspect you have only updated to null safety recently as well. This is one of the reasons why the example app should be used as issues can often open with key details being omitted. With null safety, this plugin can't have default initialisation settings for each platform. You'll need to specify these for each of your target platform. The example app would've been updated to accommodate these changes so when you bump your dependencies, check changelog and look at the history of differences in the example app that happens when there are breaking changes

@MaikuB
Copy link
Owner

MaikuB commented Oct 30, 2021

Closing this as there's no been further updates as previous info would indicate a configuration issue. Feel free to re-open if you encounter a bug and can provide a fork that contains minimal steps to reproduce the problem

@MaikuB MaikuB closed this as completed Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants