我正在寻找一种在用户收到推送通知时显示应用程序图标徽章的方法。
我使用 Firebase_messaging 插件处理推送通知,使用 flutter_app_badger 处理应用图标徽章。但我想将两者结合起来,以便在不打开应用程序的情况下在图标上设置数字。有可能做到这一点吗?还是我从 firebase_messaging 插件中忽略了一些明显的东西?
对不起,可怕的解释。我希望有人能帮助我解决这个问题。
我正在使用 flutter 本地通知在我的应用程序中显示日程通知。但不幸的是,当应用程序处于终止状态时它不起作用。
这是我的代码:
class Notifications {
static final FlutterLocalNotificationsPlugin _notifications =
FlutterLocalNotificationsPlugin();
static Future<NotificationDetails> _notificationDetails() async {
return const NotificationDetails(
android: AndroidNotificationDetails(
'weekly notification channel id',
'weekly notification channel name',
channelDescription: 'weekly notification description',
playSound: true,
sound: RawResourceAndroidNotificationSound('azan1'),
importance: Importance.high,
),
iOS: IOSNotificationDetails(sound: 'azan1.mp3', presentSound: true));
}
static void init() async {
tz.initializeTimeZones();
const AndroidInitializationSettings android =
AndroidInitializationSettings('@mipmap/ic_launcher');
const IOSInitializationSettings iOS = IOSInitializationSettings();
InitializationSettings settings =
const InitializationSettings(android: android, iOS: iOS);
await _notifications.initialize(settings);
final String locationName = await FlutterNativeTimezone.getLocalTimezone(); …Run Code Online (Sandbox Code Playgroud) 我正在通过FCM和LocalPushNotifications设置推送通知,我能够在应用程序的前台状态和后台设置它。在应用程序的终止状态下,我确实收到了通知,但是当我按下它时,即使应用程序的前台和后台状态工作正常并将用户导航到终止状态下的通知屏幕,也不会发生任何操作,应用程序只是打开,并且不会导航到通知屏幕,仅打开应用程序的主屏幕。由于设备未连接,我看不到控制台日志中的错误,但是当我从模拟器启动应用程序时,这就是我启动时得到的内容:
I/flutter ( 3829): Got a message whilst in the terminated state!
I/flutter ( 3829): Message data: null
Run Code Online (Sandbox Code Playgroud)
这在pushNotifications()方法内部调用FirebaseMessaging.instance.getInitialMessage().then()...
这是里面带有注释的代码:
处理推送通知的逻辑:
Future<void> pushNotifications() async {
await Firebase.initializeApp();
RemoteMessage initialMessage =
await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) {
_handleMessage(initialMessage);
}
/// THIS IS NOT WORKING, IT OPENS THE APP BUT DOESN'T NAVIGATE TO THE DESIRED SCREEN
///gives you the message on which user taps
///and it opened the app from terminated state
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage message) { …Run Code Online (Sandbox Code Playgroud) firebase flutter firebase-cloud-messaging flutter-notification flutter-local-notification
我正在尝试使用 flutter_local_notifications 包通过我的应用程序推送本地通知,并且与 FlutterNotificationsPlugin 一样,不推荐使用“.schedule”我尝试使用“.zonedSchedule”,但它需要 TZDateTime 值。
var androidDetails = AndroidNotificationDetails(t.id, "Task Notifier",
"Notifies if you have a task scheduled at a particular time");
var generalNotificationDetails =
NotificationDetails(android: androidDetails);
var now = DateTime.now();
var scheduledTime = DateTime(
now.year, now.month, _dayTasks.date.day, t.time.hour, t.time.minute)
.subtract(Duration(minutes: 5));
//use zonedSchedule once you figure out how to convert datetime to TZdatetime
// await notifications.zonedSchedule(
// 0, "Task", t.description, scheduledTime, generalNotificationDetails,
// androidAllowWhileIdle: true,
// uiLocalNotificationDateInterpretation:
// UILocalNotificationDateInterpretation.wallClockTime);
await notifications.schedule(0, "Ideal Day Task", t.description,
scheduledTime, generalNotificationDetails);
Run Code Online (Sandbox Code Playgroud) 我正在使用:flutter_local_notifications:^5.0.0+3
我正在显示这样的通知,一切正常。自定义图标也有效。但我试图设置一个大图标,但它只是没有显示。这是没有任何大图标的通知的屏幕截图:
更新 - 当我锁定手机时会显示,并且通知显示在锁定屏幕上。但是,当它在屏幕上弹出时,它不会显示。另外,当我向下滑动并查看列表中的所有通知时,它不会显示。仅在锁定屏幕上。为什么会这样呢?
这是我的代码:
class _MyAppState extends State<MyApp> {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
FirebaseMessaging messaging = FirebaseMessaging.instance;
@override
void initState() {
notificationPermission();
initMessaging();
subscribeToTopic('test');
createChannel();
super.initState();
}
// users unique token
void getToken() async {
print(await messaging.getToken());
}
@override
Widget build(BuildContext context) {
getToken();
// showNotification();
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(title: Text('AppBar Demo')),
),
);
}
void notificationPermission() async {
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true, …Run Code Online (Sandbox Code Playgroud) 我正在使用 Flutter 很棒的通知。当应用程序关闭时单击通知时,我想将其定向到应用程序内的特殊页面。对我来说最简单的方法是什么?
我正在开发一个android启动器,其中一个功能会延缓所有其他通知,我在一个名为“Morph”的应用程序中看到了这一点,在该应用程序中,它会将您带到“设置”->“通知访问”,您需要在其中授予该应用程序权限所有通知访问。
我想知道如何使用 Flutter 做到这一点,以及在被授予通知访问权限后,如何使用它来禁用 Flutter 中其他应用程序的通知。谢谢!
NotificationManager编辑:这显然可以在 android 开发中使用它来完成cancel(),那么在 flutter 中可以用什么替代方案呢?
我想当我的应用程序在后台运行时显示推送通知。
我正在使用flutter_local_notifications包和firebase_messaging包。
当我的应用程序是后台时,推送通知与 firebase_messaging 配合得很好。
然而,下面的方法:
// The following handler is called, when App is in the background.
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
Run Code Online (Sandbox Code Playgroud)
RemoteNotification如果对象通过以下方式传递,则不会被调用RemoteMessage:
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print('message from background handler');
print("Handling a background message: ${message.messageId}");
// If this is null, then this handler method is called
RemoteNotification remoteNotification = message.notification;
showNotificationFromData(message.data);
}
Run Code Online (Sandbox Code Playgroud)
因此,我必须传递message.dataa 对象Map<String, dynamic>。
firebaseMessagingBackgroundHandler我的问题是,当调用此处理程序方法时,我不再收到推送通知。
所以我一直在尝试使用该flutter_local_notification包来显示推送通知,但正如所说,它是“本地”的,因此它在前台工作正常,但显然不在后台(相同的代码,具有相同的数据没有显示在背景作为推送通知)。
问题 :
我需要调用firebaseMessagingBackgroundHandler处理程序来处理我的应用程序中的事件。那么当我的应用程序在后台时我可以做些什么仍然有推送通知吗?
谢谢
我正在使用 Windows 笔记本电脑和 Android 模拟器,并且我还更新了 build.gradle 文件。我收到错误
var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
在显示通知方法中。谁能帮我这个?
这是代码片段 代码片段
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';
class NotifyHelper {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin(); //
initializeNotification() async {
//tz.initializeTimeZones();
final DarwinInitializationSettings initializationSettingsDarwin =
DarwinInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
final AndroidInitializationSettings initializationSettingsAndroid =
const AndroidInitializationSettings("appicon");
final InitializationSettings initializationSettings =
InitializationSettings(
iOS: initializationSettingsDarwin,
android: initializationSettingsAndroid,
);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onDidReceiveNotificationResponse: onDidReceiveNotificationResponse);
}
displayNotification({required String title, required String body}) async {
print("doing test");
var androidPlatformChannelSpecifics = new AndroidNotificationDetails( …Run Code Online (Sandbox Code Playgroud) 我制作了一个应用程序,并实现了推送通知,它可以工作,但我尝试使用 a 更改默认图标image.png,但它没有按我预期的方式工作。这是我的通知的样子:
我希望我的图标看起来像这样:
我在我的 Android 清单中添加了以下内容:
<!-- Add custom icon to the notifications -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notifications" />
<!-- Change the color of the icon -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorPrimary" />
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么,但你能帮助我吗?
icons android push-notification flutter flutter-notification