diff --git a/README.md b/README.md index 8bbfb09..34f73f3 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,72 @@ # Wakeup/Alarm Clock PhoneGap/Cordova Plugin -### Platform Support +## Platform Support This plugin supports PhoneGap/Cordova apps running on both iOS and Android. -### Version Requirements +## Version Requirements This plugin is meant to work with Cordova 3.5.0+. ## Installation -#### Automatic Installation using PhoneGap/Cordova CLI (iOS and Android) -1. Make sure you update your projects to Cordova iOS version 3.5.0+ before installing this plugin. +### Automatic Installation using PhoneGap/Cordova CLI (iOS and Android) - cordova platform update ios - cordova platform update android +1) Make sure you update your projects to Cordova iOS version 3.5.0+ before installing this plugin. -2. Install this plugin using PhoneGap/Cordova cli: + ```terminal + cordova platform update ios + cordova platform update android + ``` - cordova plugin add https://github.com/wnyc/cordova-plugin-wakeuptimer.git +2) Install this plugin using PhoneGap/Cordova cli: + + ```terminal + cordova plugin add https://github.com/wnyc/cordova-plugin-wakeuptimer.git + ``` ## Usage - // all responses from the audio player are channeled through successCallback and errorCallback +```javascript +// all responses from the audio player are channeled through successCallback and errorCallback - // set wakeup timer - window.wakeuptimer.wakeup( successCallback, - errorCallback, - // a list of alarms to set - { - alarms : [{ - type : 'onetime', - time : { hour : 14, minute : 30 }, - extra : { message : 'json containing app-specific information to be posted when alarm triggers' }, - message : 'Alarm has expired!' - }] - } - ); +// set wakeup timer +window.wakeuptimer.wakeup( successCallback, + errorCallback, + // a list of alarms to set + { + alarms : [{ + type : 'onetime', + time : { hour : 14, minute : 30 }, + extra : { message : 'json containing app-specific information to be posted when alarm triggers' }, + message : 'Alarm has expired!' + }] + } +); - // snooze... - window.wakeuptimer.snooze( successCallback, - errorCallback, - { - alarms : [{ - type : 'snooze', - time : { seconds : 60 }, // snooze for 60 seconds - extra : { }, // json containing app-specific information to be posted when alarm triggers - message : this.get('message'), - sound : this.get('sound'), - action : this.get('action') - }] - } - ); +// snooze... +window.wakeuptimer.snooze( successCallback, + errorCallback, + { + alarms : [{ + type : 'snooze', + time : { seconds : 60 }, // snooze for 60 seconds + extra : { }, // json containing app-specific information to be posted when alarm triggers + message : this.get('message'), + sound : this.get('sound'), + action : this.get('action') + }] + } + ); - // example of a callback method - var successCallback = function(result) { - if (result.type==='wakeup') { - console.log('wakeup alarm detected--' + result.extra); - } else if(result.type==='set'){ - console.log('wakeup alarm set--' + result); - } else { - console.log('wakeup unhandled type (' + result.type + ')'); - } - }; +// example of a callback method +var successCallback = function(result) { + if (result.type==='wakeup') { + console.log('wakeup alarm detected--' + result.extra); + } else if(result.type==='set'){ + console.log('wakeup alarm set--' + result); + } else { + console.log('wakeup unhandled type (' + result.type + ')'); + } +}; +``` \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..94401ea --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "cordova-plugin-wakeuptimer", + "version": "1.0.2", + "description": "This plugin supports PhoneGap/Cordova apps running on both iOS and Android.", + "cordova": { + "id": "org.nypr.cordova.wakeupplugin", + "platforms": [ + "android", + "ios" + ] + }, + "repository": { + "type": "git", + "url": "git+https://github.com/wnyc/cordova-plugin-wakeuptimer.git" + }, + "keywords": [ + "cordova", + "ios", + "android", + "wakeup", + "timer", + "wakeuptimer", + "ecosystem:cordova", + "cordova-ios", + "cordova-android" + ], + "bugs": { + "url": "https://github.com/wnyc/cordova-plugin-wakeuptimer/issues" + }, + "homepage": "https://github.com/wnyc/cordova-plugin-wakeuptimer#readme" +} diff --git a/plugin.xml b/plugin.xml index 4e34c9b..f903f10 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="1.0.2"> WakeupTimer Wakeup Plugin Apache 2.0 diff --git a/src/android/WakeupPlugin.java b/src/android/WakeupPlugin.java index 62e3b38..1771729 100644 --- a/src/android/WakeupPlugin.java +++ b/src/android/WakeupPlugin.java @@ -195,7 +195,11 @@ protected static void setNotification(Context context, String type, Calendar ala intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent sender = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - if (Build.VERSION.SDK_INT>=19) { + + if (Build.VERSION.SDK_INT >= 23) { + // This method will be triggered even with doze mode activated (limited to once per 9 minutes per app) + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alarmDate.getTimeInMillis(), sender); + } else if (Build.VERSION.SDK_INT >= 19) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmDate.getTimeInMillis(), sender); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, alarmDate.getTimeInMillis(), sender);