浏览代码

Bugfix: Android notification is shown when the app is not running.

Sebastián Katzer 12 年之前
父节点
当前提交
aacd804f86
共有 4 个文件被更改,包括 15 次插入0 次删除
  1. 1 0
      README.md
  2. 9 0
      src/android/LocalNotification.java
  3. 3 0
      src/android/Receiver.java
  4. 2 0
      src/android/Restore.java

+ 1 - 0
README.md

@@ -46,6 +46,7 @@ cordova plugin rm de.appplant.cordova.plugin.local-notifications
 - [bugfix:] `cancel` on iOS did not work do to wrong param type.
 - [enhancement:] `cancel` & `cancelAll` remove the notification(s) from notification center as well on Android.
 - [bugfix:] Missing background callback on Android.
+- [bugfix:] Android notification is not shown when the app is not running.
 
 #### Version 0.6.0 (16.11.2013)
 - Added WP8 support<br>

+ 9 - 0
src/android/LocalNotification.java

@@ -193,6 +193,15 @@ public class LocalNotification extends CordovaPlugin {
         editor.commit();
     }
 
+    /**
+     * Set the application context if not already set.
+     */
+    public static void setContext (Context context) {
+        if (this.context == null) {
+            this.context = context;
+        }
+    }
+
     /**
      * The Local storage for the application.
      */

+ 3 - 0
src/android/Receiver.java

@@ -54,6 +54,9 @@ public class Receiver extends BroadcastReceiver {
         this.context = context;
         this.options = options;
 
+        // The context may got lost if the app was not running before
+        LocalNotification.setContext(context);
+
         if (options.getInterval() == 0) {
             LocalNotification.unpersist(options.getId());
         } else if (isFirstAlarmInFuture()) {

+ 2 - 0
src/android/Restore.java

@@ -40,6 +40,8 @@ public class Restore extends BroadcastReceiver {
                 JSONArray args  = new JSONArray(alarms.getString(alarmId, ""));
                 Options options = new Options(context).parse(args.getJSONObject(0));
 
+                // The context got lost after reboot
+                LocalNotification.setContext(context);
                 LocalNotification.add(options);
 
             } catch (JSONException e) {}