7
7
import android .content .Intent ;
8
8
import android .content .pm .ApplicationInfo ;
9
9
import android .content .pm .PackageManager ;
10
+ import android .net .Uri ;
10
11
import android .os .Bundle ;
11
12
import android .support .v4 .app .NotificationCompat ;
12
13
@@ -35,9 +36,12 @@ public static IterableNotification createNotification(Context context, Bundle ex
35
36
int stringId = context .getApplicationInfo ().labelRes ;
36
37
String applicationName = context .getString (stringId );
37
38
String notificationBody = null ;
39
+ String soundName = null ;
40
+
38
41
if (extras .containsKey (IterableConstants .ITERABLE_DATA_KEY )) {
39
42
notificationBody = extras .getString (IterableConstants .ITERABLE_DATA_BODY , notificationBody );
40
43
applicationName = extras .getString (IterableConstants .ITERABLE_DATA_TITLE , applicationName );
44
+ soundName = extras .getString (IterableConstants .ITERABLE_DATA_SOUND , soundName );
41
45
}
42
46
43
47
Intent mainIntentWithExtras = new Intent (IterableConstants .ACTION_NOTIF_OPENED );
@@ -48,22 +52,39 @@ public static IterableNotification createNotification(Context context, Bundle ex
48
52
PendingIntent notificationClickedIntent = PendingIntent .getActivity (context , 0 ,
49
53
mainIntentWithExtras , PendingIntent .FLAG_UPDATE_CURRENT );
50
54
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
+ }
62
84
63
85
notificationBuilder .setContentIntent (notificationClickedIntent );
64
86
notificationBuilder .isGhostPush = IterableHelper .isGhostPush (extras );
65
87
66
-
67
88
try {
68
89
ApplicationInfo info = context .getPackageManager ().getApplicationInfo (context .getPackageName (), PackageManager .GET_META_DATA );
69
90
notificationBuilder .setColor (info .metaData .getInt (IterableConstants .NOTIFICATION_COLOR ));
@@ -72,12 +93,13 @@ public static IterableNotification createNotification(Context context, Bundle ex
72
93
}
73
94
74
95
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 ;
79
98
}
80
99
100
+
101
+ notificationBuilder .setDefaults (notifPermissions .defaults );
102
+
81
103
return notificationBuilder ;
82
104
}
83
105
0 commit comments