标签: flutter-local-notification

Flutter 本地通知在真实设备(Android)上不起作用

我正在使用 Flutter 构建 Android 应用程序。我的应用程序需要显示本地通知。我正在使用这个包,https://pub.dev/packages/flutter_local_notifications。当我在模拟器上显示通知时,它正在工作。但当我编译发布 APK 并将其安装在实际设备上时,它不起作用。

这是NotificationService类

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationService
{
  static FlutterLocalNotificationsPlugin? flip;

  static FlutterLocalNotificationsPlugin getFlipInstance()
  {
    if (flip == null) {
      flip = FlutterLocalNotificationsPlugin();

      // app_icon needs to be a added as a drawable
      // resource to the Android head project.
      var android = const AndroidInitializationSettings('@mipmap/ic_launcher');
      var ios = const IOSInitializationSettings();

      var settings = InitializationSettings(android: android, iOS: ios);
      flip!.initialize(settings);
    }

    return flip as FlutterLocalNotificationsPlugin;
  }


  static Future showNotification(String title, String body) async {
    var …
Run Code Online (Sandbox Code Playgroud)

android dart flutter flutter-local-notification

5
推荐指数
0
解决办法
1189
查看次数

如何生成唯一的id,flutter

我正在制作一个带有通知的待办事项应用程序,并使用 flutter 本地通知插件,如何生成一个唯一的整数作为特定待办事项的 id,以便我还可以使用该唯一整数取消该特定待办事项的通知。

unique-id flutter flutter-local-notification

5
推荐指数
1
解决办法
7482
查看次数

firebase 和 flutter 本地通知都处理后台通知

当后台 firebase 中的应用程序首先处理通知,然后 flutter 本地通知在屏幕上显示弹出窗口以使 firebase 不显示通知时,我面临显示双重通知的问题

ps 删除
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);

使应用程序不处理后台通知

FirebaseMessaging.onMessage.listen(
      (RemoteMessage? message) async {
      
        _showNotification(
            id: 0,
            title: message?.notification?.title ?? '',
            body: message?.notification?.body ?? '');
      },
    );

    FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
Run Code Online (Sandbox Code Playgroud)

firebaseMessagingBackgroundHandler:

Future<void> firebaseMessagingBackgroundHandler(RemoteMessage? message) async {

  _showNotification(
      id: 0,
      title: message?.notification?.title ?? '',
      body: message?.notification?.body ?? '');

}
Run Code Online (Sandbox Code Playgroud)

firebase 包在通知标志中包含标题和正文,即使应用程序在后台工作,以任何方式使通知仅由 flutter_local_notification 包处理

push-notification flutter firebase-cloud-messaging flutter-local-notification

5
推荐指数
1
解决办法
2475
查看次数

从推送通知 flutter_local_notification 包导航到屏幕

我正在使用 flutter_local_notification 包来处理来自第三方服务器的通知(不是 firebase 云消息传递)。因为我使用的是 firebase 但不是 firebase 消息传递,所以我使用的是 flutter-local_notification 包的 onSelectNotification 函数。

这是我传递给 onSelectNotification 的函数:

static _selectNotification(String payload, StreamChatClient client, RemoteMessage message) {
    debugPrint('notification payload: $payload');

    if(payload.contains('livestream')) {
      Utils.db.getLiveRoom(payload.split(":")[1]).then((liveRoom) {
        Navigator.push(
          NavigationService.navigatorKey.currentContext!,
          MaterialPageRoute<void>(builder: (context) => LiveRoomChat(liveRoom: liveRoom)),
        );
      });
    }
    else {
      List<String> ids = message.data['channel_id'].toString().split('_');
      String receiverId = '';
      if(ids[0] == Utils.user?.uid) {
        receiverId = ids[1];
      }
      else {
        receiverId = ids[0];
      }

      Navigator.push(
        NavigationService.navigatorKey.currentContext!,
        MaterialPageRoute<void>(builder: (context) => MessageApi(
            sourceType: Utils.friends.containsKey(receiverId) ? SourceType.friends : SourceType.justMet,
            receiverId: receiverId,
            channelId: …
Run Code Online (Sandbox Code Playgroud)

push-notification flutter flutter-local-notification

5
推荐指数
1
解决办法
735
查看次数

Flutter调度本地通知不起作用

我试图在某个时间创建通知,但它不起作用。该代码不会引发任何错误,但设备上不会显示任何通知。我正在使用flutter_local_notifications

生成通知的代码:

Future<void> showNotification(
  int hour, int id, String title, String body) async {
await flutterLocalNotificationsPlugin.zonedSchedule(
  id,
  title,
  body,
  _convertTime(hour),
  const NotificationDetails(
    android: AndroidNotificationDetails('main_channel', 'Main Channel',
        channelDescription: "ashwin",
        importance: Importance.max,
        priority: Priority.max),
    iOS: IOSNotificationDetails(
      sound: 'default.wav',
      presentAlert: true,
      presentBadge: true,
      presentSound: true,
    ),
  ),
  uiLocalNotificationDateInterpretation:
      UILocalNotificationDateInterpretation.absoluteTime,
  androidAllowWhileIdle: true,
);
}
Run Code Online (Sandbox Code Playgroud)

_converTime函数代码:

TZDateTime _convertTime(int hour) {
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
tz.TZDateTime scheduleDate =
    tz.TZDateTime(tz.local, now.year, now.month, now.day, hour, 47);
return scheduleDate;
}
Run Code Online (Sandbox Code Playgroud)

该函数的结果是正确的,如下:2022-07-14 12:47:00.000Z

但是,如果我不使用此函数,而是将其更改为

Future<void> showNotification(
  int …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-local-notification

4
推荐指数
1
解决办法
2529
查看次数

backgroundHandler 需要是静态函数或顶级函数才能作为 Flutter 入口点进行访问

嘿伙计们,当我在flutter_local_notification中使用 onDidReceiveBackgroundNotificationResponse 时,我收到错误有人可以帮助我吗?

这是错误

这是我的代码

实际上我想在用户在后台模式下选择我的通知后导航到第二页,但我遇到了这个问题

flutter flutter-test flutter-local-notification

4
推荐指数
1
解决办法
5373
查看次数

未处理的异常:PlatformException(exact_alarms_not_permission,不允许精确警报,null,null)

我正在开发一个使用flutter_local_notifications的 flutter 应用程序,以便向用户发送每日通知。目前,在我的模拟器上运行 flutter 应用程序时,出现以下错误:

E / flutter(9973):[错误:flutter/runtime/dart_vm_initializer.cc(41)]未处理的异常:PlatformException(exact_alarms_not_permission,不允许精确警报,null,null)

并且应用程序冻结。这是导致错误的代码:

Future<void> repeatNotification() async {
  
  const AndroidNotificationDetails androidNotificationDetails =
      AndroidNotificationDetails(
          'repeating channel id', 'repeating channel name',
          channelDescription: 'repeating description');
  const NotificationDetails notificationDetails =
      NotificationDetails(android: androidNotificationDetails);
  
  // Create a list of greetings
  List<String> greetings = [
    "Hi!",
    "Hey there!",
    "Hello!",
    "Hi there!",
    "What's up?",
    "Howdy!",
  ];
  
  // Create a list of daily check-in messages
  List<String> checkInMessages = [
    "It's time for your daily check in.",
    "Don't forget to check in today.", …
Run Code Online (Sandbox Code Playgroud)

android flutter flutter-local-notification

3
推荐指数
1
解决办法
3292
查看次数

为什么 flutter 本地通知会出现异常

我正在尝试使用以下依赖项在 android 上发送颤振通知:

“flutter_local_notifications:^9.0.1”

但当我单击“测试”按钮时,它给了我这个错误。

任何人都知道我该如何解决它?

/////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////

在main.dart中:

 ElevatedButton(
      onPressed: () => NotificationApi.showNotification(
          title: 'Samira', body: 'Heyy theree !!!', payload: 'samira'),
      child: Text("test"),

Run Code Online (Sandbox Code Playgroud)

在notification.dart中:

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationApi {
  static final _notifications = FlutterLocalNotificationsPlugin();

  static Future _notificationDetails() async {
    return const NotificationDetails(
      android: AndroidNotificationDetails(
        'channel id',
        'channel name',
        channelDescription: 'channel description',
        importance: Importance.max,
      ),
      //iOS: IOSNotificationDetails(),
    );
  }

  static Future showNotification({
    int id = 0,
    String? title,
    String? body,
    String? payload,
  }) async =>
      _notifications.show(
        id,
        title,
        body,
        await …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-notification flutter-local-notification

1
推荐指数
1
解决办法
2398
查看次数

Flutterisolate 在 Android 上的发布模式下不起作用?

我有一个应用程序,它使用 flutterisolate 来显示本地通知。这似乎在调试模式下完美工作,甚至在通过附加真实设备的“flutter run --release --verbose”推送的发布模式下也能完美工作。然而,当发布到 Play 商店时,应用程序本身可以工作,但隔离永远不会生成 - 没有通知,也没有异常或崩溃。简直……没什么。

有什么可能导致这种行为的想法吗?什么情况会导致隔离不运行?再次 - 在调试模式下相同的代码工作起来就像一个魅力......

flutter flutter-android flutter-local-notification

1
推荐指数
1
解决办法
1649
查看次数