Browse Source

Fix `sound:null` on Android

Sebastián Katzer 11 years ago
parent
commit
5c90367891
3 changed files with 17 additions and 10 deletions
  1. 3 0
      README.md
  2. 1 1
      src/android/Options.java
  3. 13 9
      src/android/Receiver.java

+ 3 - 0
README.md

@@ -27,9 +27,11 @@ Through the [Command-line Interface](http://cordova.apache.org/docs/en/3.0.0/gui
 ```bash
 # from master:
 cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
+cordova build
 
 # stable version:
 cordova plugin add de.appplant.cordova.plugin.local-notification
+cordova build
 ```
 
 ## Removing the Plugin from your project
@@ -55,6 +57,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/413).
 - [change:] The `oncancel` callback will be called at last if `autoCancel` is set to true (iOS).
 - [bugfix:] Callbacks for non-repeating notifications were not called if they were not created in the current app instance on iOS.
 - [enhancement:] Added 'secondly' and 'minutely' as new repeat time aliases.
+- [bugfix:] `sound:null` didnt work for Android. The default sound was played.
 
 #### Version 0.7.2 (09.02.2014)
 - [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**.

+ 1 - 1
src/android/Options.java

@@ -147,7 +147,7 @@ public class Options {
             }
         }
 
-        return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
+        return null;
     }
 
     /**

+ 13 - 9
src/android/Receiver.java

@@ -117,17 +117,21 @@ public class Receiver extends BroadcastReceiver {
      */
     private Builder buildNotification () {
         Bitmap icon = BitmapFactory.decodeResource(context.getResources(), options.getIcon());
+        Uri sound   = options.getSound();
 
         Builder notification = new Notification.Builder(context)
-        .setContentTitle(options.getTitle())
-        .setContentText(options.getMessage())
-        .setNumber(options.getBadge())
-        .setTicker(options.getMessage())
-        .setSmallIcon(options.getSmallIcon())
-        .setLargeIcon(icon)
-        .setSound(options.getSound())
-        .setAutoCancel(options.getAutoCancel())
-        .setOngoing(options.getOngoing());
+            .setContentTitle(options.getTitle())
+            .setContentText(options.getMessage())
+            .setNumber(options.getBadge())
+            .setTicker(options.getMessage())
+            .setSmallIcon(options.getSmallIcon())
+            .setLargeIcon(icon)
+            .setAutoCancel(options.getAutoCancel())
+            .setOngoing(options.getOngoing());
+
+        if (sound != null) {
+            notification.setSound(sound);
+        }
 
         setClickEvent(notification);