Flutter AwesomeNotification: How schedule a notification for several days of the week? - flutter

I'm using the package awesome_notifications 0.7.4+1 and I want to schedule a notification for several days of the week (for example on Monday and on Wednesday). I thought that the NotificationCalendar is the way to go, but I only have the option to put an int after weekday: . My code example shows, how I wish it was implemented (but it isn't), so you can get a better idea of what I want.
schedule: NotificationCalendar(
weekday: [1;3],
hour: 1,
minute: 1,
timeZone: timezone,
repeats: true,
)
I am aware that there is also the option to user NotificationAndroidCrontab but I want my app to work also for iOS.
Is it even possible or do I need to create separate notifications?

Related

Flutter Local Notifications show notification every 72 hours

I am trying to send out notifications every 72 hours. I am using the flutter_local_notifications package. I know I can periodically show notifications but as far as I can see it is limited to these options:
/// The available intervals for periodically showing notifications.
enum RepeatInterval {
/// An interval for every minute.
everyMinute,
/// Hourly interval.
hourly,
/// Daily interval.
daily,
/// Weekly interval.
weekly
}
Is there any way to achieve the 72h interval? I couldn't find anything on this. Let me know if you need any more info! Any help is appreciated!
you can try this :-
fltrNotification = new FlutterLocalNotificationsPlugin();
var scheduledTime = DateTime.now().add(Duration(hour : 72));
fltrNotification.schedule(1, "Times Uppp", task,
scheduledTime, generalNotificationDetails);
always this approach works
make your own copy of package
modify it 😊
1.make your own copy
you can easily copy the package file to your project . and use it like this (flutter doc)
dependencies:
plugin1:
path: ../plugin1/
if you prefer you can fork project and use it like below
dependencies:
plugin1:
git:
url: git://github.com/flutter/plugin1.git
2.modify it 🛠
for your question you can change the value of Daily interval to (3 * Daily interval)
I found this part of code (android - ios)
I would use the flutter cron package if I were you: cron package on pub.dev
It allows you schedule a cron job which is simply a task that runs every x seconds or days, months...
For your example:
fltrNotification = new FlutterLocalNotificationsPlugin();
final cron = Cron();
// Schedule a task that will run every 3 days
cron.schedule(Schedule.parse('0 0 */3 * *'), () async {
// Schedule a notification right now
fltrNotification.schedule(1, "Times Uppp", task,
DateTime.now(), generalNotificationDetails);
print('every three days');
});
If you want to change the frequency, cron is very flexible and you can do pretty much any frequency, the cron syntax is pretty straightforward and their are some websites online that allow you to simply generate it.
There are, of course, several ways to use cron to do what you want. You could schedule a notification for the next 72 hours every 72 hours, refreshing every 24 hours, whatever seems better to you.
(I used part of Piyush Kumar's answer for this example by the way, and updated it to use cron)

Get system's first day of the week in Flutter

Is there a way of getting the first day of the week from device info or locale in Flutter? I use some libraries for which it has to be manually set, so I need to get it somehow. Or maybe, at least, these is even a library you might know which returns first day of the week by locale code?
You can use subtract method to get first day of the week according to user's device locate
DateTime today = DateTime.now();
_firstDayOfTheweek = today.subtract(new Duration(days: today.weekday));
Or you can do that with material localization and get it from context
MaterialLocalizations.of(context).firstDayOfWeekIndex;

How do I "add" time to firebase timestamp in Swift?

This question is best stated in an example:
It is currently 9:00am. User wants to do activity at 4:00pm the following day. They use UIDatePicker to select 4:00pm the next day, and then hit a button. I know firebase does times in milliseconds from 1970, so what I want to do is "add" the number of milliseconds from 9:00am to 4:00pm the following day to the ServerValue.timestamp(), like so:
activitiesRef.child(newActivity.id).setValue([
"id": newActivity.id,
"name": newActivity.name,
"isActive": newActivity.isActive,
"locString": newActivity.locationString,
"locLat": newActivity.locLat,
"locLong": newActivity.locLong,
"privacySetting": newActivity.privacySetting,
"targetTime": ServerValue.timestamp()]) // + some added value of time
//"targetTime": [".sv": "timestamp"]])
The reason for this is because I will be displaying a countdown timer elsewhere in the app until it reaches the targetTime. If I can push to firebase the targetTime, then the countdown timer will be a simple comparison of the current time on the user's phone to the targetTime itself.
The error I keep getting when trying to add a double value to the ServerValue.timestamp() is "Contextual type 'Any' cannot be used with dictionary literal"
If it is not possible to do so, what other options do I have? Thank you.
ServerValue.timestamp() is not a number that you can use to perform date arithmetic. It's a special placeholder value that the server side interprets with its sense of time.
The best you can do is write the timestamp, read it back out as a number, then perform math on it.

Is it possible to set up a clock trigger in Google Apps to send spreadsheet hourly?

I have a spreadsheet that logs incoming answered and missed calls in Google Drive.
It is currently set to send an email every hour between 10am and 7pm.
Ideally I would like it to not send the email during the weekend.
Setting up each hour Monday to Friday uses too many triggers.
Is there a way to construct a trigger that will send an email every hour (10am to 7pm) only Monday to Friday?
I've read the documentation at Google and a few (unrelated as it turns out) examples on here and I am stumped!
I tried putting a load of trigger conditions together:
function autoSendHourly() {
ScriptApp.newTrigger("hourlyUpdate()")
.timeBased()
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.onWeekDay(ScriptApp.WeekDay.TUESDAY)
.onWeekDay(ScriptApp.WeekDay.WEDNESDAY)
.onWeekDay(ScriptApp.WeekDay.THURSDAY)
.onWeekDay(ScriptApp.WeekDay.FRIDAY)
.atHour(10)
.atHour(11)
.atHour(12)
.atHour(13)
.atHour(14)
.atHour(15)
.atHour(16)
.atHour(17)
.atHour(18)
.atHour(19)
.create();
}
I wasn't entirely surprised that it didn't work, but I was mildly surprised that it threw up no errors.
Any help (including "you're mad it can't be done") would be greatly appreciated.
The simplest thing to do is use the create trigger like you did but for every hour every day and then in you handler function add a small piece of code that will return if day and time don't meet specific conditions like explained in this (old) post.
the code may look like something like this :
function officeHours(){
var nowH=new Date().getHours();
var nowD=new Date().getDay();
Logger.log('day : '+nowD+' Hours : '+nowH)
if(nowH>17||nowH<8||nowD==6||nowD==0){return}
Browser.msgBox('time to work !');//normally your real function should begin here...
}
I haven't messed around with java in awhile but this article might help.
Android: how to get the current day of the week (Monday, etc...) in the user's language?
If it was me, I would get the day of the week and check it in a switch. Then if it matches a week day call a function to check the time between 10am and 7pm.
Best of luck.

How To set Custom repeat interval For Nslocal Notification.....?

i am New to iphone Development .I Am Trying To Use NslocalNotification In My Project I Need To Give Remeinder For Every 2Hours or For Every Two Days Or For Every Two Months Etc..Currently I am Using NslocalNotification Repeat Interval .But Its Working For Only Every Minute For Every Hour using Nscalender ....
NSString *InterVal=[freQuencyArr objectAtIndex:index-2];
NSString *InterValType=[freQuencyArr objectAtIndex:index-1];
if(![InterVal isEqualToString:#"Every"])
{
result=[InterVal intValue];
}else
result=1;
if([InterValType isEqualToString:#"Day"]){
notification.repeatInterval= NSDayCalendarUnit;
}else if([InterValType isEqualToString:#"Week"]){
notification.repeatInterval= NSWeekCalendarUnit;
}
else if([InterValType isEqualToString:#"Month"]){
notification.repeatInterval= NSMonthCalendarUnit;
}else if([InterValType isEqualToString:#"days"]){
notification.repeatInterval=result*24*60*60;
}
here If result is 2 depend Up on IntervalType I Need Notification
its Not Working With Me
if([InterValType isEqualToString:#"days"]){
notification.repeatInterval=result*24*60*60;
}
#Srinivas:
If you look at the link I have posted in this answer, You will come to know that I have tried every possible solution here to try and do what you want currently.
I had tried all this to implement it in my app, but this doesn't work.
I am afraid to say this but this is not possible. It only allows the unit NSCalendarUnit objects to be set as a repeat interval.
I invested almost 2 months (I asked the question in Dec 2010 and answered it myself in February 2011) to try and implement every possible solution available on internet through different articles and different forums but none did help.
Check out my link and lookout for all the answers if something is useful to you.
How to set Local Notification repeat interval to custom time interval?
Really Hope that this helps you.
The repeatInterval property of a UILocalNotification cannot be used to repeat less than every one calendar unit, i.e. every day, every week, every month, etc.
Instead, you will have to schedule multiple notifications to achieve the desired effect, setting the fireDate property accordingly.
As lemnar says you are unable to use repeatInterval to repeat in a frequency different from the calendar units Apple provided. So, the code below:
if([InterValType isEqualToString:#"days"]){
notification.repeatInterval=result*24*60*60;
}
Will not do anything. I am also using repeat notifications in an app that I have built and the way I've gotten around this is by creating multiple notifications each repeating to give the "desired" repeat frequency. As an example, if I want to repeat "every 2 days", I can't do this using repeatInterval. However, I have a "scheduling function" in my app that creates multiple individual notifications to achieve this. I do this going out an arbitrary length of time (in my case, one week). So in the example above, when the user specifies that he / she needs a notification every two days from today, I create 3 notifications (one each for day 3, 5, and 7).
For repeating at a frequency less than a calendar unit, things are a little easier. Say I need to repeat every 12 hours (at 6AM and 6PM). Then, I would create 2 notifications (one for 6AM and another for 6PM). I would then set the repeatInterval for each of these notifications to NSDayCalendarUnit. This way I have created a set of notifications that repeat every 12 hours.
When my app loads, I go out another 7 days and recreate notifications as needed. Not the most elegant solution, but this was the best way I could think of getting around the repeatInterval limitation.