Commit 7a6e7996 by Sebastián Katzer

Improvement of repeating notifications at exact time (#44).…

Improvement of repeating notifications at exact time (#44). `AlarmManager.setRepeating` triggers the notifications at strange dates, like everything others with Android...
parent c424fbc7
......@@ -56,6 +56,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331).
- [feature:] Repeat with custom intervals on Android.
- **[bugfix:]** Callbacks are called with the ID as a number and not as a string.
- [enhancement:] The background callback on Android is called, even the app is not running when the notification is tapped.
- [enhancement:] Notifications are repeated more precisely.
#### Version 0.6.3 (12.12.2013)
- [bugfix:] Black screen on Android.
......
......@@ -114,12 +114,8 @@ public class LocalNotification extends CordovaPlugin {
AlarmManager am = getAlarmManager();
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
if (options.getInterval() > 0) {
am.setRepeating(AlarmManager.RTC_WAKEUP, triggerTime, options.getInterval(), pi);
} else {
am.set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
}
}
/**
* Cancel a specific notification that was previously registered.
......
......@@ -24,6 +24,7 @@ package de.appplant.cordova.plugin.localnotification;
import java.util.Calendar;
import java.util.Date;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
......@@ -77,6 +78,17 @@ public class Options {
}
/**
* Setzt die neue Zeit an Hand des Intervalls.
*/
public Options moveDate () {
try {
options.put("date", (getDate() + interval) / 1000);
} catch (JSONException e) {}
return this;
}
/**
* Gibt die Eigenschaften als JSONObjekt an.
*/
public JSONObject getJSONObject() {
......@@ -84,7 +96,7 @@ public class Options {
}
/**
* Gibt die Zeit in Sekunden an, wann die Notification aufpoppen soll.
* Gibt die Zeit in Millisekunden an, wann die Notification aufpoppen soll.
*/
public long getDate() {
return options.optLong("date", 0) * 1000;
......
......@@ -76,6 +76,8 @@ public class Receiver extends BroadcastReceiver {
LocalNotification.unpersist(options.getId());
} else if (isFirstAlarmInFuture()) {
return;
} else {
LocalNotification.add(options.moveDate());
}
Builder notification = buildNotification();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment