Commit 7a6e7996 authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

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
Loading
Loading
Loading
Loading
+1 −0
Changes for README.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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.
+0 −4
Changes for src/android/LocalNotification.java: 0 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -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.
+13 −1
Changes for src/android/Options.java: 13 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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;
@@ -76,6 +77,17 @@ public class Options {
        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.
     */
@@ -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;
+2 −0
Changes for src/android/Receiver.java: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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();