diff --git a/README.md b/README.md index 67d3ce1dc..60339058f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ Parameter | Description `options.android.senderID` | `String` Maps to the project number in the Google Developer Console. `options.android.icon` | `String` Optional. The name of a drawable resource to use as the small-icon. `options.android.iconColor` | `String` Optional. Sets the background color of the small icon. [Supported Formats](http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)) +`options.android.sound` | `Boolean` Optional. If `true` it plays the sound specified in the push data or the default system sound. Default is `true`. +`options.android.vibrate` | `Boolean` Optional. If `true` the device vibrates on receipt of notification. Default is `true`. `options.ios` | `JSON Object` iOS specific initialization options. `options.windows` | `JSON Object` Windows specific initialization options. diff --git a/src/android/com/adobe/phonegap/push/GCMIntentService.java b/src/android/com/adobe/phonegap/push/GCMIntentService.java index 2284e95cd..15d38f769 100644 --- a/src/android/com/adobe/phonegap/push/GCMIntentService.java +++ b/src/android/com/adobe/phonegap/push/GCMIntentService.java @@ -97,17 +97,8 @@ public void createNotification(Context context, Bundle extras) { int requestCode = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); - int defaults = Notification.DEFAULT_ALL; - - if (extras.getString("defaults") != null) { - try { - defaults = Integer.parseInt(extras.getString("defaults")); - } catch (NumberFormatException e) {} - } - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) - //.setDefaults(defaults) .setWhen(System.currentTimeMillis()) .setContentTitle(extras.getString("title")) .setTicker(extras.getString("title")) @@ -117,9 +108,20 @@ public void createNotification(Context context, Bundle extras) { SharedPreferences prefs = context.getSharedPreferences("com.adobe.phonegap.push", Context.MODE_PRIVATE); String localIcon = prefs.getString("icon", null); String localIconColor = prefs.getString("iconColor", null); + boolean soundOption = prefs.getBoolean("sound", true); + boolean vibrateOption = prefs.getBoolean("vibrate", true); Log.d(LOG_TAG, "stored icon=" + localIcon); Log.d(LOG_TAG, "stored iconColor=" + localIconColor); + Log.d(LOG_TAG, "stored sound=" + soundOption); + Log.d(LOG_TAG, "stored vibrate=" + vibrateOption); + /* + * Notification Vibration + */ + if (vibrateOption) { + mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); + } + /* * Notification Icon Color * @@ -201,17 +203,22 @@ public void createNotification(Context context, Bundle extras) { } } - String soundname = extras.getString("soundname"); - if (soundname == null) { - soundname = extras.getString("sound"); - } - if (soundname != null) { - Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE - + "://" + context.getPackageName() + "/raw/" + soundname); - Log.d(LOG_TAG, sound.toString()); - mBuilder.setSound(sound); - } else { - mBuilder.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI); + /* + * Notification Sound + */ + if (soundOption) { + String soundname = extras.getString("soundname"); + if (soundname == null) { + soundname = extras.getString("sound"); + } + if (soundname != null) { + Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + + "://" + context.getPackageName() + "/raw/" + soundname); + Log.d(LOG_TAG, sound.toString()); + mBuilder.setSound(sound); + } else { + mBuilder.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI); + } } String message = extras.getString("message"); diff --git a/src/android/com/adobe/phonegap/push/PushPlugin.java b/src/android/com/adobe/phonegap/push/PushPlugin.java index 42ca6ffcc..f60dc05a5 100644 --- a/src/android/com/adobe/phonegap/push/PushPlugin.java +++ b/src/android/com/adobe/phonegap/push/PushPlugin.java @@ -86,6 +86,8 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo } catch (JSONException e) { Log.d(LOG_TAG, "no iconColor option"); } + editor.putBoolean("sound", jo.optBoolean("sound", true)); + editor.putBoolean("vibrate", jo.optBoolean("vibrate", true)); editor.commit(); }