Skip to content

Instantly share code, notes, and snippets.

@flurrydev
Created October 19, 2018 22:16
Show Gist options
  • Select an option

  • Save flurrydev/3f7fb5f5ea1922e59795e57b6653e040 to your computer and use it in GitHub Desktop.

Select an option

Save flurrydev/3f7fb5f5ea1922e59795e57b6653e040 to your computer and use it in GitHub Desktop.
// define channel attributes (name, description, and id)
public static final String NOTIFICATION_CHANNEL_ID = "SomeChannelId"
public static final String NOTIFICATION_CHANNEL_NAME = "UserFacingChannelName"
public static final String NOTIFICATION_CHANNEL_DESCRIPTION = "User facing description of the channel"
// create notification channel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);
if (notificationChannel == null) {
// only create it if it hasn't been created already
notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription(NOTIFICATION_CHANNEL_DESCRIPTION);
notificationChannel.enableLights(true);
notificationChannel.enableVibration(true);
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
notificationManager.createNotificationChannel(notificationChannel);
}
}
// pass Flurry the channel ID while setting up Marketing Module
FlurryMarketingOptions flurryMarketingOptions = new FlurryMarketingOptions.Builder()
...
.withDefaultNotificationChannelId(NOTIFICATION_CHANNEL_ID)
...
.build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment