Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added alarm call that will work in doze mode #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 53 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 + ')');
}
};
```
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.nypr.cordova.wakeupplugin"
version="0.1.0">
version="1.0.2">
<name>WakeupTimer</name>
<description>Wakeup Plugin</description>
<license>Apache 2.0</license>
Expand Down
6 changes: 5 additions & 1 deletion src/android/WakeupPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down