Просмотр исходного кода

Allow option to setVibrate() on Android (#1356)

Chris Yuen 8 лет назад
Родитель
Сommit
0793559b6c

+ 5 - 0
src/android/notification/Builder.java

@@ -118,6 +118,7 @@ public class Builder {
         Uri sound     = options.getSoundUri();
         int smallIcon = options.getSmallIcon();
         int ledColor  = options.getLedColor();
+        long[] vibrate = options.getVibrate();
         NotificationCompat.Builder builder;
 
         builder = new NotificationCompat.Builder(context)
@@ -138,6 +139,10 @@ public class Builder {
             builder.setSound(sound);
         }
 
+        if (vibrate != null) {
+            builder.setVibrate(vibrate);
+        }
+
         if (smallIcon == 0) {
             builder.setSmallIcon(options.getIcon());
         } else {

+ 16 - 0
src/android/notification/Options.java

@@ -31,6 +31,7 @@ import android.support.v4.app.NotificationCompat;
 
 import org.json.JSONException;
 import org.json.JSONObject;
+import org.json.JSONArray;
 
 import java.util.Date;
 
@@ -318,6 +319,21 @@ public class Options {
         return uri;
     }
 
+    public long[] getVibrate() {
+        JSONArray array = options.optJSONArray("vibrate");
+
+        if (array == null)
+            return null;
+
+        long[] rv = new long[array.length()];
+
+        for (int i = 0; i < array.length(); i++) {
+            rv[i] = array.optInt(i);
+        }
+
+        return rv;
+    }
+
     /**
      * Icon bitmap for the local notification.
      */

+ 1 - 0
www/local-notification-util.js

@@ -71,6 +71,7 @@ exports.applyPlatformSpecificOptions = function () {
         defaults.ledOnTime = undefined;
         defaults.ledOffTime = undefined;
         defaults.color     = undefined;
+        defaults.vibrate   = undefined;
         break;
     }