Reputation: 589
I'm developing an Android app with Phonegap. I need to set a long-term alarm to remind users things like a monthly task.
I was searching plugins for this, but the most popular plugin that I found it doesn't have enough reliability. I've tried to use it, but it only works with short-term alarms and not always.
I asked the developer, and he says that he doesn't know why it fails.
In this situation, I intend to develop my own plugin that help me with this.
I have a medium experience with Android native but I have a question before:
¿Which is the way to set this long-term alarm with high reliability on Android, preferably without services and in the simplest way? ¿It's possible?
Of course, I want to keep the alarms even If the mobile is restarted, If the app is killed and so on.
PD: Thanks and sorry for my english level.
Upvotes: 2
Views: 1884
Reputation: 589
Katzer has rewritten all the plugin in a new version, recently I have been testing it and it seems that it runs well.
Upvotes: 2
Reputation: 3803
I don't know, which plugin you tested because you didn't mentioned it.
This Plugin from Katzer is that what you need for your scheduled reminders: https://github.com/katzer/cordova-plugin-local-notifications/
This is an example for a scheduled local notification:
window.plugin.notification.local.add({
id: String, // A unique id of the notification
date: Date, // This expects a date object
message: String, // The message that is displayed
title: String, // The title of the message
repeat: String, // Either 'secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'
badge: Number, // Displays number badge to notification
sound: String, // A sound to be played
json: String, // Data to be passed through the notification
autoCancel: Boolean, // Setting this flag and the notification is automatically cancelled when the user clicks it
ongoing: Boolean, // Prevent clearing of notification (Android only)
}, callback, scope);
This is the way, how you schedule a notification for a date in the future:
var now = new Date().getTime(),
_60_seconds_from_now = new Date(now + 60*1000);
window.plugin.notification.local.add({
id: 1,
title: 'Reminder',
message: 'Dont forget to buy some flowers.',
repeat: 'weekly',
date: _60_seconds_from_now
});
The actual time could be calculated with this script:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
document.write(today);
This should help you.
Upvotes: 2