Skip to content

Commit ab2e6c1

Browse files
committed
adds soundId and soundUrl checks for channel id and channel name
1 parent e7544bd commit ab2e6c1

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableNotificationHelper.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public IterableNotificationBuilder createNotification(Context context, Bundle ex
104104
String soundName = null;
105105
String messageId = null;
106106
String pushImage = null;
107-
int soundResourceId = 0;
107+
int soundId = 0;
108108
//TODO: When backend supports channels, these strings needs to change (channelName, channelId, channelDescription).
109109
String channelDescription = "";
110110

@@ -135,10 +135,11 @@ public IterableNotificationBuilder createNotification(Context context, Bundle ex
135135

136136
// Remove extension of sound file
137137
soundName = soundName.replaceFirst("[.][^.]+$", "");
138+
soundId = context.getResources().getIdentifier(soundName, IterableConstants.SOUND_FOLDER_IDENTIFIER, context.getPackageName());
138139
}
139140

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);
142143
IterableNotificationBuilder notificationBuilder = new IterableNotificationBuilder(context, channelId);
143144

144145
String iterableData = extras.getString(IterableConstants.ITERABLE_DATA_KEY);
@@ -277,13 +278,13 @@ private void registerChannelIfEmpty(Context context, String channelId, String ch
277278
* TODO: Remove this method if removeAllInactiveChannels is working as expected.
278279
* Safely removes unused and old channel if the configuration for notification badge is changed.
279280
*/
280-
private void removeUnusedChannel(Context context, String soundName) {
281+
private void removeUnusedChannel(Context context, String soundName, int soundId, String soundUrl) {
281282
NotificationManager mNotificationManager = (NotificationManager)
282283
context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
283284

284285
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O
285286
&& mNotificationManager != null) {
286-
String channelIdToDelete = getOldChannelId(context, soundName);
287+
String channelIdToDelete = getOldChannelId(context, soundName, soundId, soundUrl);
287288
NotificationChannel unusedChannel = mNotificationManager.getNotificationChannel(channelIdToDelete);
288289
if (unusedChannel != null) {
289290
for (StatusBarNotification activeNotification : mNotificationManager.getActiveNotifications()) {
@@ -351,18 +352,18 @@ private static boolean isNotificationBadgingEnabled(Context context) {
351352
return true;
352353
}
353354

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);
356357
}
357358

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);
360361
}
361362

362-
private String getChannelIdName(Context context, boolean isActive, String soundName) {
363+
private String getChannelIdName(Context context, boolean isActive, String soundName, int soundId, String soundUrl) {
363364
String channelId = context.getPackageName();
364365

365-
if (soundName != null && soundName != "") {
366+
if (soundName != null && soundId != 0 || soundUrl != null) {
366367
channelId = soundName;
367368
}
368369

@@ -378,14 +379,14 @@ private String getChannelIdName(Context context, boolean isActive, String soundN
378379
return channelId;
379380
}
380381

381-
private String getChannelName(String soundName) {
382+
private String getChannelName(String soundName, int soundId, String soundUrl) {
382383
String channelName = "Default";
383384

384-
if (!soundName.equals("")) {
385+
if (soundName != null && soundId != 0 || soundUrl != null) {
385386
channelName = soundName;
386387
}
387388

388-
return channelName != null ? channelName : DEFAULT_CHANNEL_NAME;
389+
return channelName;
389390
}
390391

391392
/**
@@ -477,5 +478,4 @@ private static Uri getSoundUri(Context context, String soundName) {
477478

478479
return Uri.parse(IterableConstants.ANDROID_RESOURCE_PATH + context.getPackageName() + "/" + soundID);
479480
}
480-
481481
}

0 commit comments

Comments
 (0)