Skip to content

Instantly share code, notes, and snippets.

@raystatic
Last active March 2, 2022 20:09
Show Gist options
  • Select an option

  • Save raystatic/bdac7bf996c791ec34c0e738eaf43b0c to your computer and use it in GitHub Desktop.

Select an option

Save raystatic/bdac7bf996c791ec34c0e738eaf43b0c to your computer and use it in GitHub Desktop.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
val name = NotificationConstants.CHANNEL_NAME
val description = NotificationConstants.CHANNEL_DESCRIPTION
val importance = NotificationManager.IMPORTANCE_HIGH
val channel = NotificationChannel(NotificationConstants.CHANNEL_ID,name,importance)
channel.description = description
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
notificationManager?.createNotificationChannel(channel)
}
val builder = NotificationCompat.Builder(context,NotificationConstants.CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Downloading your file...")
.setOngoing(true)
.setProgress(0,0,true)
NotificationManagerCompat.from(context).notify(NotificationConstants.NOTIFICATION_ID,builder.build())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment