Skip to content

Commit

Permalink
[Anel][COM_00004_Notification] Notification for API 26 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
AnelCC committed May 6, 2020
1 parent 7adac92 commit 775bdc3
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.anelcc.usercomunacation.notification

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
Expand All @@ -24,6 +26,19 @@ class NotificationActivity : AppCompatActivity(), View.OnClickListener {
findViewById<View>(R.id.btn_simple_notification).setOnClickListener(this)
findViewById<View>(R.id.btn_large_notification).setOnClickListener(this)
findViewById<View>(R.id.btn_action_notification).setOnClickListener(this)

// For API 26 and later, we have to create a channel otherwise the notification
// won't be displayed. This can be called multiple times without harm - if there's
// already a channel with the given ID then the call is ignored
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel(NOTIFY_CHANNEL, "Notifications", importance)
channel.description = "This is a notification channel"

// Register the channel with the system
val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager?.createNotificationChannel(channel)
}
}

override fun onClick(v: View?) {
Expand Down

0 comments on commit 775bdc3

Please sign in to comment.