2022-02-01 21:22:06 +05:30
|
|
|
package com.github.libretube
|
2021-12-14 21:45:53 +05:30
|
|
|
|
|
|
|
import android.app.Application
|
2022-05-20 17:50:26 +05:30
|
|
|
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() {
|
2022-05-20 17:50:26 +05:30
|
|
|
override fun onCreate() {
|
|
|
|
super.onCreate()
|
|
|
|
|
|
|
|
initializeNotificationChannels()
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-06-06 20:12:46 +05:30
|
|
|
* Initializes the required [NotificationChannel]s for the app.
|
2022-05-20 17:50:26 +05:30
|
|
|
*/
|
|
|
|
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-05-20 17:50:26 +05:30
|
|
|
|
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
|
2022-05-20 17:50:26 +05:30
|
|
|
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
2022-06-06 20:12:46 +05:30
|
|
|
notificationManager.createNotificationChannel(channel)
|
2022-05-20 17:50:26 +05:30
|
|
|
}
|
|
|
|
}
|
2021-12-14 21:45:53 +05:30
|
|
|
|
|
|
|
companion object {
|
|
|
|
@JvmField
|
2022-05-20 17:50:26 +05:30
|
|
|
var seekTo: Long? = 0
|
2021-12-14 21:45:53 +05:30
|
|
|
}
|
2022-05-20 17:50:26 +05:30
|
|
|
}
|