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). ...@@ -56,6 +56,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331).
- [feature:] Repeat with custom intervals on Android. - [feature:] Repeat with custom intervals on Android.
- **[bugfix:]** Callbacks are called with the ID as a number and not as a string. - **[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:] 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) #### Version 0.6.3 (12.12.2013)
- [bugfix:] Black screen on Android. - [bugfix:] Black screen on Android.
......
...@@ -114,11 +114,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -114,11 +114,7 @@ public class LocalNotification extends CordovaPlugin {
AlarmManager am = getAlarmManager(); AlarmManager am = getAlarmManager();
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
if (options.getInterval() > 0) { am.set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
am.setRepeating(AlarmManager.RTC_WAKEUP, triggerTime, options.getInterval(), pi);
} else {
am.set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
}
} }
/** /**
......
...@@ -24,6 +24,7 @@ package de.appplant.cordova.plugin.localnotification; ...@@ -24,6 +24,7 @@ package de.appplant.cordova.plugin.localnotification;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
...@@ -68,15 +69,26 @@ public class Options { ...@@ -68,15 +69,26 @@ public class Options {
} else if (repeat.equalsIgnoreCase("yearly")) { } else if (repeat.equalsIgnoreCase("yearly")) {
interval = AlarmManager.INTERVAL_DAY*365; interval = AlarmManager.INTERVAL_DAY*365;
} else { } else {
try { try {
interval = Integer.parseInt(repeat) * 60000; interval = Integer.parseInt(repeat) * 60000;
} catch (Exception e) {}; } catch (Exception e) {};
} }
return this; return this;
} }
/** /**
* 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. * Gibt die Eigenschaften als JSONObjekt an.
*/ */
public JSONObject getJSONObject() { public JSONObject getJSONObject() {
...@@ -84,7 +96,7 @@ public class Options { ...@@ -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() { public long getDate() {
return options.optLong("date", 0) * 1000; return options.optLong("date", 0) * 1000;
......
...@@ -76,6 +76,8 @@ public class Receiver extends BroadcastReceiver { ...@@ -76,6 +76,8 @@ public class Receiver extends BroadcastReceiver {
LocalNotification.unpersist(options.getId()); LocalNotification.unpersist(options.getId());
} else if (isFirstAlarmInFuture()) { } else if (isFirstAlarmInFuture()) {
return; return;
} else {
LocalNotification.add(options.moveDate());
} }
Builder notification = buildNotification(); 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