Skip to content

Instantly share code, notes, and snippets.

@fardavide
Last active May 3, 2019 13:57
Show Gist options
  • Save fardavide/b761ac2946e6706163c6127fbe69497f to your computer and use it in GitHub Desktop.
Save fardavide/b761ac2946e6706163c6127fbe69497f to your computer and use it in GitHub Desktop.
val notificationManager = context.getSystemService<NotificationManager>()!!
val title = context.getString( R.string.cache_cleaned_title )
val id = context.getString( R.id.cache_cleaned_id ).toInt()
val channelId = context.getString( R.string.background_group_id )
val channelName = context.getString( R.string.background_group_name )
val notification = NotificationCompat.Builder( context, channelId )
.setSmallIcon( R.drawable.ic_app )
.setContentTitle( title )
.setPriority( NotificationCompat.PRIORITY_LOW )
.build()
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
val channel = NotficationChannel(
channelId, channelName, NotificationManager.IMPORTANCE_LOW
)
notificationManager.createNotificationChannel( channel )
}
notificationManager.notify( id, notification )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment