Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Create a Notification that is shown as a heads-up notification if possible.
- *
- * For this project, this is used to show a notification so that you know when different steps
- * of the background work chain are starting
- *
- * @param message Message shown on the notification
- * @param context Context needed to create Toast
- *
- * Created by Arindam Karmakar on 16/5/19.
- */
- internal fun makeStatusNotification(message: String, context: Context) {
- // Make a channel if necessary
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- // Create the NotificationChannel, but only on API 26+ because
- // the NotificationChannel class is new and not in the support library
- val name = VERBOSE_NOTIFICATION_CHANNEL_NAME
- val description = VERBOSE_NOTIFICATION_CHANNEL_DESCRIPTION
- val importance = NotificationManager.IMPORTANCE_HIGH
- val channel = NotificationChannel(CHANNEL_ID, name, importance)
- channel.description = description
- // Add the channel
- val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
- notificationManager?.createNotificationChannel(channel)
- }
- // Create the notification
- val builder = NotificationCompat.Builder(context, CHANNEL_ID)
- .setSmallIcon(R.drawable.ic_launcher_foreground)
- .setContentTitle(NOTIFICATION_TITLE)
- .setContentText(message)
- .setPriority(NotificationCompat.PRIORITY_HIGH)
- .setVibrate(LongArray(0))
- // Show the notification
- NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, builder.build())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement