Commit 7d7dfe63 by Sebastián Katzer

Sound can be specified under Android.

parent 0e4e2230
...@@ -30,6 +30,9 @@ cordova plugin rm de.appplant.cordova.plugin.local-notifications ...@@ -30,6 +30,9 @@ cordova plugin rm de.appplant.cordova.plugin.local-notifications
``` ```
## Release Notes ## Release Notes
#### Version 0.6.1 (not yet released)
- [feature:] Sound can be specified under Android.
#### Version 0.6.0 (16.11.2013) #### Version 0.6.0 (16.11.2013)
- Added WP8 support<br> - Added WP8 support<br>
*Based on the LiveTiles WP8 plugin made by* ***Jesse MacFadyen (purplecabbage)*** *Based on the LiveTiles WP8 plugin made by* ***Jesse MacFadyen (purplecabbage)***
...@@ -63,6 +66,7 @@ window.plugin.notification.local.add({ ...@@ -63,6 +66,7 @@ window.plugin.notification.local.add({
title: String, // the title of the message title: String, // the title of the message
repeat: String, // has the options of daily', 'weekly',''monthly','yearly') repeat: String, // has the options of daily', 'weekly',''monthly','yearly')
badge: Number, // displays number badge to notification badge: Number, // displays number badge to notification
sound: String, // a sound to be played (iOS & Android)
foreground: String, // a javascript function to be called if the app is running foreground: String, // a javascript function to be called if the app is running
background: String, // a javascript function to be called if the app is in the background background: String, // a javascript function to be called if the app is in the background
}); });
...@@ -120,6 +124,27 @@ window.plugin.notification.local.add({ icon: 'ic_launcher' }); ...@@ -120,6 +124,27 @@ window.plugin.notification.local.add({ icon: 'ic_launcher' });
*/ */
window.plugin.notification.local.add({ icon: 'ic_dialog_email' }); window.plugin.notification.local.add({ icon: 'ic_dialog_email' });
``` ```
### Notification sound under Android
The default sound is `RingtoneManager.TYPE_NOTIFICATION`. But an specific sound can be dinfed through the `sound` property.<br>
The sound must be a absolute or relative Uri pointing to the sound file.
```javascript
/**
* Plays the sound if the notification pop's up.
*/
window.plugin.notification.local.add({ sound: 'res/sounds/beep.mp3' });
/**
* Plays the `RingtoneManager.TYPE_ALARM` sound.
*/
window.plugin.notification.local.add({ sound: 'TYPE_ALARM' });
/**
* Plays no sound if the notification pop's up.
*/
window.plugin.notification.local.add({ sound: null });
```
### Notification sound under iOS ### Notification sound under iOS
The sound must be located in your project's resources and must be a caf file. The sound must be located in your project's resources and must be a caf file.
```javascript ```javascript
...@@ -140,6 +165,7 @@ window.plugin.notification.local.add({ image: 'appdata:ApplicationIcon.png' }) ...@@ -140,6 +165,7 @@ window.plugin.notification.local.add({ image: 'appdata:ApplicationIcon.png' })
``` ```
All images can be restored to the default ones by canceling the notification. All images can be restored to the default ones by canceling the notification.
## Quirks ## Quirks
### Adding a notification under WP8 ### Adding a notification under WP8
An application can only display one notification at a time. Each time a new notification has to be added, the application live tile's data will be overwritten by the new ones. An application can only display one notification at a time. Each time a new notification has to be added, the application live tile's data will be overwritten by the new ones.
......
...@@ -15,6 +15,9 @@ import java.util.Date; ...@@ -15,6 +15,9 @@ import java.util.Date;
import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaInterface;
import org.json.JSONObject; import org.json.JSONObject;
import android.media.RingtoneManager;
import android.net.Uri;
/** /**
* Class that helps to store the options that can be specified per alarm. * Class that helps to store the options that can be specified per alarm.
*/ */
...@@ -91,8 +94,20 @@ public class LocalNotificationOptions { ...@@ -91,8 +94,20 @@ public class LocalNotificationOptions {
/** /**
* Gibt den Pfad zum Sound der Notification an. * Gibt den Pfad zum Sound der Notification an.
*/ */
public String getSound () { public Uri getSound () {
return options.optString("sound", null); String sound = options.optString("sound", null);
if (sound != null) {
try {
int soundId = (Integer) RingtoneManager.class.getDeclaredField(sound).get(Integer.class);
return RingtoneManager.getDefaultUri(soundId);
} catch (Exception e) {
return Uri.parse(sound);
}
}
return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
} }
/** /**
......
...@@ -103,17 +103,8 @@ public class LocalNotificationReceiver extends BroadcastReceiver { ...@@ -103,17 +103,8 @@ public class LocalNotificationReceiver extends BroadcastReceiver {
.setContentText(options.getMessage()) .setContentText(options.getMessage())
.setNumber(options.getBadge()) .setNumber(options.getBadge())
.setTicker(options.getTitle()) .setTicker(options.getTitle())
.setSmallIcon(options.getIcon()); .setSmallIcon(options.getIcon())
.setSound(options.getSound());
try {
if (isInBackground(context)) {
// app is in background
notification.setDefaults(Notification.DEFAULT_SOUND);
}
} catch (Exception e) {
// missing GET_TASKS permission
notification.setDefaults(Notification.DEFAULT_SOUND);
}
setClickEvent(notification); setClickEvent(notification);
......
...@@ -31,7 +31,8 @@ LocalNotification.prototype = { ...@@ -31,7 +31,8 @@ LocalNotification.prototype = {
switch (device.platform) { switch (device.platform) {
case 'Android': case 'Android':
defaults.icon = 'icon'; break; defaults.icon= 'icon';
defaults.sound = null; break;
case 'iOS': case 'iOS':
defaults.sound = ''; break; defaults.sound = ''; break;
case 'WinCE': case 'Win32NT': case 'WinCE': case 'Win32NT':
......
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