From b011c9a579c0a1e3fad567270dc3018322133578 Mon Sep 17 00:00:00 2001 From: Maksim Chemerisuk Date: Thu, 12 Mar 2015 19:48:36 +0300 Subject: [PATCH] add custom sound support for android --- src/android/com/plugin/gcm/GCMIntentService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/android/com/plugin/gcm/GCMIntentService.java b/src/android/com/plugin/gcm/GCMIntentService.java index caee145e..7cc15815 100644 --- a/src/android/com/plugin/gcm/GCMIntentService.java +++ b/src/android/com/plugin/gcm/GCMIntentService.java @@ -91,6 +91,13 @@ public void createNotification(Context context, Bundle extras) PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); int defaults = Notification.DEFAULT_ALL; + String sound = extras.getString("sound"); + + if (sound != null) { + sound = sound.substring(0, sound.lastIndexOf('.')); + // override defaults value for custom sound + defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE; + } if (extras.getString("defaults") != null) { try { @@ -106,7 +113,8 @@ public void createNotification(Context context, Bundle extras) .setContentTitle(extras.getString("title")) .setTicker(extras.getString("title")) .setContentIntent(contentIntent) - .setAutoCancel(true); + .setAutoCancel(true) + .setSound(android.net.Uri.parse("android.resource://" + context.getPackageName() + "/raw/" + sound)); String message = extras.getString("message"); if (message != null) {