Skip to content

Commit 1e5f02c

Browse files
authored
Merge pull request #505 from Iterable/MOB-5664-Revert-Channel-Name-Implementation
[MOB-5664] - Revert channel name implementation
2 parents f785400 + bcd3bb1 commit 1e5f02c

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public final class IterableConstants {
143143
public static final String NOTIFICATION_ICON_NAME = "iterable_notification_icon";
144144
public static final String NOTIFICAION_BADGING = "iterable_notification_badging";
145145
public static final String NOTIFICATION_COLOR = "iterable_notification_color";
146-
public static final String NOTIFICATION_CHANNEL_NAME = "Default";
146+
public static final String NOTIFICATION_CHANNEL_NAME = "iterable_notification_channel_name";
147147
public static final String DEFAULT_SOUND = "default";
148148
public static final String SOUND_FOLDER_IDENTIFIER = "raw";
149149
public static final String ANDROID_RESOURCE_PATH = "android.resource://";

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Map;
2727

2828
class IterableNotificationHelper {
29+
private static final String DEFAULT_CHANNEL_NAME = "iterable channel";
2930
private static final String NO_BADGE = "_noBadge";
3031

3132
@VisibleForTesting
@@ -139,8 +140,8 @@ public IterableNotificationBuilder createNotification(Context context, Bundle ex
139140
soundUri = getSoundUri(context, soundName, soundUrl);
140141

141142
String channelName = (soundUri == Settings.System.DEFAULT_NOTIFICATION_URI)
142-
? IterableConstants.NOTIFICATION_CHANNEL_NAME
143-
: getChannelName(soundName);
143+
? getChannelName(context)
144+
: soundName;
144145

145146
String channelId = (soundUri == Settings.System.DEFAULT_NOTIFICATION_URI)
146147
? context.getPackageName()
@@ -357,14 +358,33 @@ private String getChannelIdName(Context context, boolean isActive, String soundN
357358
return channelId;
358359
}
359360

360-
private String getChannelName(String soundName) {
361-
String channelName = IterableConstants.NOTIFICATION_CHANNEL_NAME;
362-
363-
if (soundName != null) {
364-
channelName = soundName;
361+
private String getChannelName(Context context) {
362+
String channelName = null;
363+
try {
364+
ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
365+
if (info.metaData != null) {
366+
Object channelNameMetaData = info.metaData.get(IterableConstants.NOTIFICATION_CHANNEL_NAME);
367+
if (channelNameMetaData instanceof String) {
368+
// Literal string value
369+
channelName = (String) channelNameMetaData;
370+
} else if (channelNameMetaData instanceof Integer) {
371+
// Try to read from a string resource
372+
int stringId = (Integer) channelNameMetaData;
373+
if (stringId != 0) {
374+
channelName = context.getString(stringId);
375+
}
376+
}
377+
IterableLogger.d(IterableNotificationBuilder.TAG, "channel name: " + channelName);
378+
}
379+
} catch (Exception e) {
380+
IterableLogger.e(IterableNotificationBuilder.TAG, "Error while retrieving channel name", e);
365381
}
366382

367-
return channelName;
383+
if (channelName != null) {
384+
return channelName;
385+
} else {
386+
return DEFAULT_CHANNEL_NAME;
387+
}
368388
}
369389

370390
/**

0 commit comments

Comments
 (0)