Skip to content

Commit 2cf5eef

Browse files
authored
Merge pull request #90 from Iterable/feature/MOB-146-notification-color-resource
[MOB-146] Add support for color resources in iterable_notification_color
2 parents 6578e22 + 9b1be29 commit 2cf5eef

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ Add this line to `AndroidManifest.xml` to specify the notification color:
194194
```
195195
where `#FFFFFF` can be replaced with a hex representation of a color of your choice. In stock Android, the notification icon and action buttons will be tinted with this color.
196196

197+
You can also use a color resource:
198+
```xml
199+
<meta-data android:name="iterable_notification_color" android:resource="@color/notification_color"/>
200+
```
201+
197202
#### Notification channel name
198203

199204
Since Android 8.0, Android requires apps to specify a channel for every notification. Iterable uses one channel for all notification; to customize the name of this channel, add this to `AndroidManifest.xml`:

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.content.pm.ApplicationInfo;
1010
import android.content.pm.PackageManager;
1111
import android.content.pm.ResolveInfo;
12+
import android.content.res.Resources;
1213
import android.graphics.Bitmap;
1314
import android.graphics.BitmapFactory;
1415
import android.net.Uri;
@@ -227,7 +228,11 @@ public static IterableNotificationBuilder createNotification(Context context, Bu
227228
try {
228229
ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
229230
if (info.metaData != null) {
230-
notificationBuilder.setColor(info.metaData.getInt(IterableConstants.NOTIFICATION_COLOR));
231+
int color = info.metaData.getInt(IterableConstants.NOTIFICATION_COLOR);
232+
try {
233+
color = context.getResources().getColor(color);
234+
} catch (Resources.NotFoundException ignored) {}
235+
notificationBuilder.setColor(color);
231236
}
232237
} catch (PackageManager.NameNotFoundException e) {
233238
e.printStackTrace();

0 commit comments

Comments
 (0)