LibreTube/app/src/main/java/com/github/libretube/MyApp.kt

55 lines
1.6 KiB
Kotlin
Raw Normal View History

2022-02-01 21:22:06 +05:30
package com.github.libretube
2021-12-14 21:45:53 +05:30
import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.os.Build
2021-12-14 21:45:53 +05:30
2022-06-05 15:12:33 +05:30
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
initializeNotificationChannels()
}
/**
2022-06-06 20:12:46 +05:30
* Initializes the required [NotificationChannel]s for the app.
*/
private fun initializeNotificationChannels() {
2022-06-06 20:12:46 +05:30
createNotificationChannel(
"download_service",
"Download Service",
"DownloadService",
NotificationManager.IMPORTANCE_NONE
)
createNotificationChannel(
"background_mode",
"Background Mode",
"Shows a notification with buttons to control the audio player",
NotificationManager.IMPORTANCE_LOW
)
}
2022-06-06 20:12:46 +05:30
private fun createNotificationChannel(
id: String,
name: String,
descriptionText: String,
importance: Int
) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(id, name, importance)
channel.description = descriptionText
// Register the channel in the system
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
2022-06-06 20:12:46 +05:30
notificationManager.createNotificationChannel(channel)
}
}
2021-12-14 21:45:53 +05:30
companion object {
@JvmField
var seekTo: Long? = 0
2021-12-14 21:45:53 +05:30
}
}