Я создаю класс Notification с методом, который инициализирует Notification Builder. Первый параметр NotificationCompat.Builder
является переменной Context
. Я предоставляю this
для параметра, но получаю следующую ошибку:
Несоответствие типов: Требуется: Контекст найден: Уведомление
Ошибка возникает в первой строке в коде моей функции setNotificationAtTime
Ниже мой код:
package com.example.notificationapp
import android.app.PendingIntent.getActivity
import android.content.Context
import androidx.core.app.NotificationCompat
import java.security.AccessController.getContext
import java.util.*
class Notification(title:String, description:String, date: Date) {
// Attributes
private var description:String = ""
// Initialization
init {
// Download the constructor parameters into the object's variables
this.description = description
}
// Getters
fun getDescription():String {
return description
}
// Setters
fun setDescription(newDescription:String) {
this.description = newDescription;
}
// Method to set the notification at a specific time
fun setNotificationAtTime(time:Date) {
val builder = NotificationCompat.Builder(this,
"com.example.notificationapp")
}
}