77import android .content .Intent ;
88import android .content .pm .ApplicationInfo ;
99import android .content .pm .PackageManager ;
10+ import android .net .Uri ;
1011import android .os .Bundle ;
1112import android .support .v4 .app .NotificationCompat ;
1213
@@ -35,9 +36,12 @@ public static IterableNotification createNotification(Context context, Bundle ex
3536 int stringId = context .getApplicationInfo ().labelRes ;
3637 String applicationName = context .getString (stringId );
3738 String notificationBody = null ;
39+ String soundName = null ;
40+
3841 if (extras .containsKey (IterableConstants .ITERABLE_DATA_KEY )) {
3942 notificationBody = extras .getString (IterableConstants .ITERABLE_DATA_BODY , notificationBody );
4043 applicationName = extras .getString (IterableConstants .ITERABLE_DATA_TITLE , applicationName );
44+ soundName = extras .getString (IterableConstants .ITERABLE_DATA_SOUND , soundName );
4145 }
4246
4347 Intent mainIntentWithExtras = new Intent (IterableConstants .ACTION_NOTIF_OPENED );
@@ -48,22 +52,39 @@ public static IterableNotification createNotification(Context context, Bundle ex
4852 PendingIntent notificationClickedIntent = PendingIntent .getActivity (context , 0 ,
4953 mainIntentWithExtras , PendingIntent .FLAG_UPDATE_CURRENT );
5054
51- IterableNotification notificationBuilder = new IterableNotification (
52- context );
53- notificationBuilder
54- .setDefaults (Notification .DEFAULT_SOUND )
55- .setSmallIcon (getIconId (context ))
56- .setTicker (applicationName ).setWhen (0 )
57- .setAutoCancel (true )
58- .setContentTitle (applicationName )
59- .setStyle (new NotificationCompat .BigTextStyle ().bigText (notificationBody ))
60- .setPriority (Notification .PRIORITY_HIGH )
61- .setContentText (notificationBody );
55+ Notification notifPermissions = new Notification ();
56+ notifPermissions .defaults |= Notification .DEFAULT_LIGHTS ;
57+
58+ IterableNotification notificationBuilder = new IterableNotification (context );
59+ notificationBuilder
60+ .setSmallIcon (getIconId (context ))
61+ .setTicker (applicationName ).setWhen (0 )
62+ .setAutoCancel (true )
63+ .setContentTitle (applicationName )
64+ .setStyle (new NotificationCompat .BigTextStyle ().bigText (notificationBody ))
65+ .setPriority (Notification .PRIORITY_HIGH )
66+ .setContentText (notificationBody );
67+
68+ if (soundName != null ) {
69+ //Removes the file type from the name
70+ String [] soundFile = soundName .split ("\\ ." );
71+ soundName = soundFile [0 ];
72+
73+ if (!soundName .equalsIgnoreCase (IterableConstants .DEFAULT_SOUND )){
74+ int soundID = context .getResources ().getIdentifier (soundName , IterableConstants .SOUND_FOLDER_IDENTIFIER , context .getPackageName ());
75+ Uri soundUri = Uri .parse (IterableConstants .ANDROID_RESOURCE_PATH + context .getPackageName () + "/" + soundID );
76+ notificationBuilder .setSound (soundUri );
77+ } else {
78+ notifPermissions .defaults |= Notification .DEFAULT_SOUND ;
79+ }
80+
81+ } else {
82+ notifPermissions .defaults |= Notification .DEFAULT_SOUND ;
83+ }
6284
6385 notificationBuilder .setContentIntent (notificationClickedIntent );
6486 notificationBuilder .isGhostPush = IterableHelper .isGhostPush (extras );
6587
66-
6788 try {
6889 ApplicationInfo info = context .getPackageManager ().getApplicationInfo (context .getPackageName (), PackageManager .GET_META_DATA );
6990 notificationBuilder .setColor (info .metaData .getInt (IterableConstants .NOTIFICATION_COLOR ));
@@ -72,12 +93,13 @@ public static IterableNotification createNotification(Context context, Bundle ex
7293 }
7394
7495 PackageManager pm = context .getPackageManager ();
75- if (pm .checkPermission ("android.permission.VIBRATE" , context .getPackageName ()) == PackageManager .PERMISSION_GRANTED ) {
76- notificationBuilder .setDefaults (Notification .DEFAULT_ALL );
77- } else {
78- notificationBuilder .setVibrate (null );
96+ if (pm .checkPermission (android .Manifest .permission .VIBRATE , context .getPackageName ()) == PackageManager .PERMISSION_GRANTED ) {
97+ notifPermissions .defaults |= Notification .DEFAULT_VIBRATE ;
7998 }
8099
100+
101+ notificationBuilder .setDefaults (notifPermissions .defaults );
102+
81103 return notificationBuilder ;
82104 }
83105
0 commit comments