|
26 | 26 | import java.util.Map;
|
27 | 27 |
|
28 | 28 | class IterableNotificationHelper {
|
| 29 | + private static final String DEFAULT_CHANNEL_NAME = "iterable channel"; |
29 | 30 | private static final String NO_BADGE = "_noBadge";
|
30 | 31 |
|
31 | 32 | @VisibleForTesting
|
@@ -139,8 +140,8 @@ public IterableNotificationBuilder createNotification(Context context, Bundle ex
|
139 | 140 | soundUri = getSoundUri(context, soundName, soundUrl);
|
140 | 141 |
|
141 | 142 | String channelName = (soundUri == Settings.System.DEFAULT_NOTIFICATION_URI)
|
142 |
| - ? IterableConstants.NOTIFICATION_CHANNEL_NAME |
143 |
| - : getChannelName(soundName); |
| 143 | + ? getChannelName(context) |
| 144 | + : soundName; |
144 | 145 |
|
145 | 146 | String channelId = (soundUri == Settings.System.DEFAULT_NOTIFICATION_URI)
|
146 | 147 | ? context.getPackageName()
|
@@ -357,14 +358,33 @@ private String getChannelIdName(Context context, boolean isActive, String soundN
|
357 | 358 | return channelId;
|
358 | 359 | }
|
359 | 360 |
|
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); |
365 | 381 | }
|
366 | 382 |
|
367 |
| - return channelName; |
| 383 | + if (channelName != null) { |
| 384 | + return channelName; |
| 385 | + } else { |
| 386 | + return DEFAULT_CHANNEL_NAME; |
| 387 | + } |
368 | 388 | }
|
369 | 389 |
|
370 | 390 | /**
|
|
0 commit comments