mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-30 05:43:00 -08:00
44 lines
1.2 KiB
Kotlin
44 lines
1.2 KiB
Kotlin
package com.kunzisoft.keepass.notifications
|
|
|
|
import android.content.Intent
|
|
import android.util.Log
|
|
import com.kunzisoft.keepass.R
|
|
|
|
class DatabaseTaskNotificationService : NotificationService() {
|
|
|
|
private val notificationId = 532
|
|
|
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
|
if (intent == null) {
|
|
Log.w(TAG, "null intent")
|
|
} else {
|
|
newNotification(intent.getIntExtra(DATABASE_TASK_TITLE_KEY, R.string.saving_database))
|
|
}
|
|
return START_NOT_STICKY
|
|
}
|
|
|
|
private fun newNotification(title: Int) {
|
|
|
|
val builder = buildNewNotification()
|
|
.setSmallIcon(R.drawable.notification_ic_data_usage_24dp)
|
|
.setContentTitle(getString(title))
|
|
.setAutoCancel(false)
|
|
.setContentIntent(null)
|
|
startForeground(notificationId, builder.build())
|
|
}
|
|
|
|
override fun onDestroy() {
|
|
|
|
notificationManager?.cancel(notificationId)
|
|
|
|
super.onDestroy()
|
|
}
|
|
|
|
companion object {
|
|
|
|
private val TAG = DatabaseTaskNotificationService::class.java.name
|
|
|
|
const val DATABASE_TASK_TITLE_KEY = "DatabaseTaskTitle"
|
|
}
|
|
|
|
} |