How to schedule yearly notifications in flutter using the "flutter_local_notifications" library
String repeatType = "Yearly";
await flutterLocalNotificationsPlugin.zonedSchedule(
_id,
"Title",
"Body",
_nextInstanceOfTenAM(time, true),
NotificationDetails(
android: AndroidNotificationDetails(_id, "Title", channelDescription: "Body"),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: repeatType == "Daily"
? DateTimeComponents.time
: repeatType == "Weekly"
? DateTimeComponents.dayOfWeekAndTime
: repeatType == "Monthly"
? DateTimeComponents.dayOfMonthAndTime
: *<CODE HERE>*,
);
Examples of recurring notifications
DateTimeComponents.time (Daily)
DateTimeComponents.dayOfWeekAndTime (Weekly)
DateTimeComponents.dayOfMonthAndTime (Monthly)
I'm trying to implement Yearly notifications using the constant values
DateTimeComponents.values.
It accepts a List of DateTimeComponents. But there is no documentation about how the variable would look like
Does anybody know the solution to this?
Related
I want to set sound when push notification, but problem is app when update or install then sound is work ok and when i push local notification and change file of sound but sound notification not change follow. it still takes the old sound.
var platformChannelSpecificsAndroid = new AndroidNotificationDetails(
"fcm_default_channel",
"fcm_default_channel",
channelDescription: 'Channel to Received Push Notification',
playSound: true,
styleInformation: DefaultStyleInformation(true, true),
importance: Importance.max,
priority: Priority.high,
icon: 'launch_background',
sound: RawResourceAndroidNotificationSound(pushSound ?? ""),
);
var platformChannelSpecificsIos = new IOSNotificationDetails(
// presentSound: true
sound: pushSound ?? "");
var platformChannelSpecifics = new NotificationDetails(
android: platformChannelSpecificsAndroid,
iOS: platformChannelSpecificsIos);
new Future.delayed(Duration.zero, () {
flutterLocalNotificationsPlugin.show(
hashCode,
pushTitle,
pushText,
platformChannelSpecifics,
payload: payloadT,
);
});
I saw the same problem. I found this answer Play multiple different notification sounds from app . But it is only helpful for Kotlin
I have a problem with Android repeating notifications (used Notifee library version "#notifee/react-native": "^4.1.0"). The notification is fired many times on some devices and must be killed from app settings. Looks like a never-ending loop of the same notification.
The problem found so far in these 2 situations: 1) the user doesn't use the app for a few days and then opens it (despite we are not scheduling notification in any hook, it's on the button), 2) the user had fly mode at the time of notification.
Notification set with this code:
notifee.createTriggerNotification(notification, trigger);
trigger:
{
alarmManager: {
allowWhileIdle: true,
},
type: TriggerType.TIMESTAMP,
timestamp: fireDate,
repeatFrequency: RepeatFrequency.WEEKLY,
};
notification:
{
title: alertTitle,
body: alertBody,
data: userInfo,
android: {
channelId,
importance: AndroidImportance.HIGH,
pressAction: {
id: 'default',
launchActivity: 'default',
launchActivityFlags: [AndroidLaunchActivityFlag.SINGLE_TOP],
},
smallIcon: 'ic_small_icon',
largeIcon: 'ic_launcher',
style: alertBody
? {
type: AndroidStyle.BIGTEXT,
text: alertBody,
}
: undefined,
showTimestamp: true,
visibility: AndroidVisibility.PUBLIC,
sound: 'default',
},
ios: {
sound: 'default',
foregroundPresentationOptions: {
sound: true,
alert: true,
badge: true,
},
},
};
Have you ever noticed similar behavior? Any ideas on what can cause it?
How do you use a custom channel with a local notification in Expo SDK 39 with Android?
On the topic of notifications, the Expo documentation seems to include a mishmash of instructions for both depreciated and the current version of Expo.
The documentation for LegacyNotifications mentions that a “LocalNotification” object can include configuration for “channelId”.
And, in fact, the legacy methods are what the current notification guide says to use:
Notifications.presentLocalNotificationAsync({
title: 'New Message',
body: 'Message!!!!',
android: {
channelId: 'chat-messages',
},
});
But, in multiple places, the documentation says to NOT use the legacy methods:
“This API is deprecated and will be removed in the SDK 40. Please, check the new notification module.”
“Instead of presentNotificationAsync developers are encouraged to use setNotificationHandler and scheduleNotificationAsync.”
Using the current API, I’m able to create a custom channel, ‘messages’, using “setNotificationChannelAsync”:
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('messages', {
name: 'Messages',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
The documentation gives the following simple example for using “scheduleNotificationAsync”:
async function schedulePushNotification() {
await Notifications.scheduleNotificationAsync({
content: {
title: "You've got mail! 📬",
body: 'Here is the notification body',
data: { data: 'goes here' },
},
trigger: { seconds: 2 },
});
}
According to the documentation, the only argument that “scheduleNotificationAsync” takes is “NotificationRequestInput,” which in turn can include “NotificationContentInput”. However, I did not see any mention of channelId.
Is there a way to use a custom channelId in scheduleNotificationAsync?
Folks on the Expo forums pointed out that NotificationRequestInput includes both NotificationContentInput and NotificationTriggerInput. The documentation for the NotificationTriggerInput types includes channelId.
Expanding upon the example for scheduleNotificationAsync, the simplest use of channelId would be
async function schedulePushNotification() {
await Notifications.scheduleNotificationAsync({
content: {
title: "You've got mail! 📬",
body: "Here is the notification body",
data: { data: "goes here" },
},
trigger: {
seconds: 2,
channelId: "messages",
},
});
}
My flutter app, show this notification when FCM is triggered.
await flutterLocalNotificationsPlugin.show(
0, "my app. Alert", "Alert text from App", platform
);
Is there any way to show a image in the notification bar and not only the text?
Something like:
await flutterLocalNotificationsPlugin.show(
0, "my app. Alert", "Alert text from App","url: myimage.com/sample.jpg", platform
);
Thanks
If you are using the flutter_local_notifications plugin, then you can do something like this for android:
Future<void> _showBigPictureNotification() async {
var largeIconPath = await _downloadAndSaveImage(
'http://via.placeholder.com/48x48', 'largeIcon');
var bigPicturePath = await _downloadAndSaveImage(
'http://via.placeholder.com/400x800', 'bigPicture');
var bigPictureStyleInformation = BigPictureStyleInformation(
bigPicturePath, BitmapSource.FilePath,
largeIcon: largeIconPath,
largeIconBitmapSource: BitmapSource.FilePath,
contentTitle: 'overridden <b>big</b> content title',
htmlFormatContentTitle: true,
summaryText: 'summary <i>text</i>',
htmlFormatSummaryText: true);
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'big text channel id',
'big text channel name',
'big text channel description',
style: AndroidNotificationStyle.BigPicture,
styleInformation: bigPictureStyleInformation);
var platformChannelSpecifics =
NotificationDetails(androidPlatformChannelSpecifics, null);
await flutterLocalNotificationsPlugin.show(
0, 'big text title', 'silent body', platformChannelSpecifics);
}
For more such examples, please refer the official example provided by the plugin developer, here.
I am trying to speed up notifications delivery on firebase notifications.
Because sometimes it might take 10 seconds to get the notification.
Currently I am using this message to send notification with admin.messaging().send(message).
const message = {
notification: {
title: 'Immediate Notification',
body: 'Important Message',
},
data: {
title: 'data',
body: 'some data'
},
android: {
ttl: 1000,
"notification": {
"sound": "default"
}
},
apns: {
headers: {
"apns-expiration": "1000",
},
payload: {
aps: {
badge: 1,
"sound": "default"
},
},
},
};
I am not sure if the speed will increase.
Need Clerification:-
1) If I put "apns-priority": "10" for iOS ? and priority high for android ? Something like this:
headers: {"apns-priority": "10"}
"android":{"priority":"high"},
2) If I set Time To Live to 0 ? ttl:0 and "apns-expiration": 0
3) If I don't send anything in data object ?
Or maybe there are any other way to speed them up ?