@@ -104,7 +104,7 @@ public IterableNotificationBuilder createNotification(Context context, Bundle ex
104
104
String soundName = null ;
105
105
String messageId = null ;
106
106
String pushImage = null ;
107
- int soundResourceId = 0 ;
107
+ int soundId = 0 ;
108
108
//TODO: When backend supports channels, these strings needs to change (channelName, channelId, channelDescription).
109
109
String channelDescription = "" ;
110
110
@@ -135,10 +135,11 @@ public IterableNotificationBuilder createNotification(Context context, Bundle ex
135
135
136
136
// Remove extension of sound file
137
137
soundName = soundName .replaceFirst ("[.][^.]+$" , "" );
138
+ soundId = context .getResources ().getIdentifier (soundName , IterableConstants .SOUND_FOLDER_IDENTIFIER , context .getPackageName ());
138
139
}
139
140
140
- String channelName = getChannelName (soundName );
141
- String channelId = getCurrentChannelId (context , soundName );
141
+ String channelName = getChannelName (soundName , soundId , soundUrl );
142
+ String channelId = getCurrentChannelId (context , soundName , soundId , soundUrl );
142
143
IterableNotificationBuilder notificationBuilder = new IterableNotificationBuilder (context , channelId );
143
144
144
145
String iterableData = extras .getString (IterableConstants .ITERABLE_DATA_KEY );
@@ -277,13 +278,13 @@ private void registerChannelIfEmpty(Context context, String channelId, String ch
277
278
* TODO: Remove this method if removeAllInactiveChannels is working as expected.
278
279
* Safely removes unused and old channel if the configuration for notification badge is changed.
279
280
*/
280
- private void removeUnusedChannel (Context context , String soundName ) {
281
+ private void removeUnusedChannel (Context context , String soundName , int soundId , String soundUrl ) {
281
282
NotificationManager mNotificationManager = (NotificationManager )
282
283
context .getApplicationContext ().getSystemService (Context .NOTIFICATION_SERVICE );
283
284
284
285
if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .O
285
286
&& mNotificationManager != null ) {
286
- String channelIdToDelete = getOldChannelId (context , soundName );
287
+ String channelIdToDelete = getOldChannelId (context , soundName , soundId , soundUrl );
287
288
NotificationChannel unusedChannel = mNotificationManager .getNotificationChannel (channelIdToDelete );
288
289
if (unusedChannel != null ) {
289
290
for (StatusBarNotification activeNotification : mNotificationManager .getActiveNotifications ()) {
@@ -351,18 +352,18 @@ private static boolean isNotificationBadgingEnabled(Context context) {
351
352
return true ;
352
353
}
353
354
354
- private String getCurrentChannelId (Context context , String soundName ) {
355
- return getChannelIdName (context , true , soundName );
355
+ private String getCurrentChannelId (Context context , String soundName , int soundId , String soundUrl ) {
356
+ return getChannelIdName (context , true , soundName , soundId , soundUrl );
356
357
}
357
358
358
- private String getOldChannelId (Context context , String soundName ) {
359
- return getChannelIdName (context , false , soundName );
359
+ private String getOldChannelId (Context context , String soundName , int soundId , String soundUrl ) {
360
+ return getChannelIdName (context , false , soundName , soundId , soundUrl );
360
361
}
361
362
362
- private String getChannelIdName (Context context , boolean isActive , String soundName ) {
363
+ private String getChannelIdName (Context context , boolean isActive , String soundName , int soundId , String soundUrl ) {
363
364
String channelId = context .getPackageName ();
364
365
365
- if (soundName != null && soundName != "" ) {
366
+ if (soundName != null && soundId != 0 || soundUrl != null ) {
366
367
channelId = soundName ;
367
368
}
368
369
@@ -378,14 +379,14 @@ private String getChannelIdName(Context context, boolean isActive, String soundN
378
379
return channelId ;
379
380
}
380
381
381
- private String getChannelName (String soundName ) {
382
+ private String getChannelName (String soundName , int soundId , String soundUrl ) {
382
383
String channelName = "Default" ;
383
384
384
- if (! soundName . equals ( "" ) ) {
385
+ if (soundName != null && soundId != 0 || soundUrl != null ) {
385
386
channelName = soundName ;
386
387
}
387
388
388
- return channelName != null ? channelName : DEFAULT_CHANNEL_NAME ;
389
+ return channelName ;
389
390
}
390
391
391
392
/**
@@ -477,5 +478,4 @@ private static Uri getSoundUri(Context context, String soundName) {
477
478
478
479
return Uri .parse (IterableConstants .ANDROID_RESOURCE_PATH + context .getPackageName () + "/" + soundID );
479
480
}
480
-
481
481
}
0 commit comments