Я использую AlarmManager для отправки сигнала тревоги и BroadcastReceiver для получения этого сигнала тревоги.
Мое приложение также использует базу данных комнат с NotificationDao.
Мне нужно кое-что добавить с «upsertNotification» при получении сигнала тревоги.
Как я могу это заархивировать?
BroadcastReceiver:
class AlarmReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val message = intent?.getStringExtra("EXTRA_MESSAGE") ?: return
val notificationType =
NotificationType.fromValue(intent.getIntExtra("NOTIFICATION_TYPE", 0))
val notification = Notification(
id = null,
date = LocalDate.now(),
time = LocalTime.now(),
title = "Test Title Premium",
description = message,
unread = true,
notificationType = NotificationType.PremiumAdvertising.value
)
context?.let { DayReminderNotificationService(it) }?.showNotification(message)
}
}
NotificationDao:
@Dao
interface NotificationDao {
@Upsert
suspend fun upsertNotification(notification: Notification)
@Delete
suspend fun deleteNotification(notification: Notification)
@Query("SELECT * FROM notifications")
fun getAllNotifications(): Flow
@Query("SELECT * FROM notifications WHERE unread = 1")
fun getAllUnreadNotifications(): Flow
}
@Module
@InstallIn(SingletonComponent::class)
object CoreModule {
@Provides
@Singleton
fun provideNotificationDao(database: AppDatabase) = database.notificationDao()
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... r-room-dao
Kotlin BroadcastReceiver Room Dao ⇐ Android
Форум для тех, кто программирует под Android
1734263469
Anonymous
Я использую AlarmManager для отправки сигнала тревоги и BroadcastReceiver для получения этого сигнала тревоги.
Мое приложение также использует базу данных комнат с NotificationDao.
Мне нужно кое-что добавить с «upsertNotification» при получении сигнала тревоги.
Как я могу это заархивировать?
BroadcastReceiver:
class AlarmReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val message = intent?.getStringExtra("EXTRA_MESSAGE") ?: return
val notificationType =
NotificationType.fromValue(intent.getIntExtra("NOTIFICATION_TYPE", 0))
val notification = Notification(
id = null,
date = LocalDate.now(),
time = LocalTime.now(),
title = "Test Title Premium",
description = message,
unread = true,
notificationType = NotificationType.PremiumAdvertising.value
)
context?.let { DayReminderNotificationService(it) }?.showNotification(message)
}
}
NotificationDao:
@Dao
interface NotificationDao {
@Upsert
suspend fun upsertNotification(notification: Notification)
@Delete
suspend fun deleteNotification(notification: Notification)
@Query("SELECT * FROM notifications")
fun getAllNotifications(): Flow
@Query("SELECT * FROM notifications WHERE unread = 1")
fun getAllUnreadNotifications(): Flow
}
@Module
@InstallIn(SingletonComponent::class)
object CoreModule {
@Provides
@Singleton
fun provideNotificationDao(database: AppDatabase) = database.notificationDao()
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79282252/kotlin-broadcastreceiver-room-dao[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия