AirshipNotificationProvider implements NotificationProvider { @NonNull @Override public NotificationArguments onCreateNotificationArguments(@NonNull Context context, @NonNull PushMessage message) { String requestedChannelId = message.getNotificationChannel(getDefaultNotificationChannelId()); String activeChannelId = NotificationChannelUtils.getActiveChannel(requestedChannelId, DEFAULT_NOTIFICATION_CHANNEL); return NotificationArguments.newBuilder(message) .setNotificationChannelId(activeChannelId) .setNotificationId(message.getNotificationTag(), getNextId(context, message)) .build(); } AirshipNotificationProvider(@NonNull Context context, @NonNull AirshipConfigOptions configOptions); void setDefaultTitle(@StringRes int titleId); @StringRes int getDefaultTitle(); void setSmallIcon(@DrawableRes int smallIconId); @DrawableRes int getSmallIcon(); void setLargeIcon(@DrawableRes int largeIcon); @DrawableRes int getLargeIcon(); void setDefaultAccentColor(@ColorInt int accentColor); @ColorInt int getDefaultAccentColor(); void setDefaultNotificationChannelId(@NonNull String channel); @NonNull String getDefaultNotificationChannelId(); @NonNull @Override NotificationArguments onCreateNotificationArguments(@NonNull Context context, @NonNull PushMessage message); @NonNull @Override NotificationResult onCreateNotification(@NonNull Context context, @NonNull NotificationArguments arguments); @Override void onNotificationCreated(@NonNull Context context, @NonNull Notification notification, @NonNull NotificationArguments arguments); static final int TAG_NOTIFICATION_ID; }
@Test public void testArgumentsFallbackChannel() { NotificationArguments arguments = provider.onCreateNotificationArguments(context, pushMessage); assertEquals("test_channel", arguments.getNotificationChannelId()); assertEquals(pushMessage, arguments.getMessage()); assertEquals(AirshipNotificationProvider.TAG_NOTIFICATION_ID, arguments.getNotificationId()); assertEquals("some-tag", arguments.getNotificationTag()); assertFalse(arguments.getRequiresLongRunningTask()); }
@Test public void testArgumentsWithChannel() { Bundle extras = new Bundle(); extras.putString(PushMessage.EXTRA_ALERT, "Test Push Alert!"); extras.putString(PushMessage.EXTRA_PUSH_ID, "0a2027a0-1766-11e4-9db0-90e2ba287ae5"); extras.putString(PushMessage.EXTRA_NOTIFICATION_CHANNEL, "cool-channel"); extras.putString(PushMessage.EXTRA_NOTIFICATION_TAG, "some-tag"); createChannel("cool-channel"); pushMessage = new PushMessage(extras); NotificationArguments arguments = provider.onCreateNotificationArguments(context, pushMessage); assertEquals("cool-channel", arguments.getNotificationChannelId()); assertEquals(pushMessage, arguments.getMessage()); assertEquals(AirshipNotificationProvider.TAG_NOTIFICATION_ID, arguments.getNotificationId()); assertEquals("some-tag", arguments.getNotificationTag()); assertFalse(arguments.getRequiresLongRunningTask()); }