@@ -216,28 +216,22 @@ object VideoDownloadManager {
216216 service.startForeground(1 , notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC )
217217 }
218218
219- private fun createNotificationChannel (context : Context ) {
220- if (SDK_INT >= Build .VERSION_CODES .O ) {
221- val channel = NotificationChannel (
222- DOWNLOAD_CHANNEL_ID ,
223- DOWNLOAD_CHANNEL_NAME ,
224- NotificationManager .IMPORTANCE_DEFAULT
225- ).apply {
226- description = DOWNLOAD_CHANNEL_DESCRIPT
219+ private fun Context.createNotificationChannel () {
220+ hasCreatedNotChanel = true
221+ // Create the NotificationChannel, but only on API 26+ because
222+ // the NotificationChannel class is new and not in the support library
223+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
224+ val name = DOWNLOAD_CHANNEL_NAME // getString(R.string.channel_name)
225+ val descriptionText = DOWNLOAD_CHANNEL_DESCRIPT // getString(R.string.channel_description)
226+ val importance = NotificationManager .IMPORTANCE_DEFAULT
227+ val channel = NotificationChannel (DOWNLOAD_CHANNEL_ID , name, importance).apply {
228+ description = descriptionText
227229 }
228- val notificationManager = context.getSystemService(NotificationManager ::class .java)
230+ // Register the channel with the system
231+ val notificationManager: NotificationManager =
232+ this .getSystemService(Context .NOTIFICATION_SERVICE ) as NotificationManager
229233 notificationManager.createNotificationChannel(channel)
230234 }
231- hasCreatedNotChanel = true
232- }
233-
234- private fun createNotification (context : Context ): Notification {
235- val builder = NotificationCompat .Builder (context, DOWNLOAD_CHANNEL_ID )
236- .setContentTitle(" Downloading Video" )
237- .setContentText(" Your video is downloading in the background." )
238-
239- // Add actions (e.g., Resume, Pause, Stop) if needed
240- return builder.build()
241235 }
242236
243237 // /** Will return IsDone if not found or error */
@@ -503,7 +497,7 @@ object VideoDownloadManager {
503497 }
504498
505499 if (! hasCreatedNotChanel) {
506- createNotificationChannel(context )
500+ context. createNotificationChannel()
507501 }
508502
509503 val notification = builder.build()
@@ -2038,4 +2032,4 @@ object VideoDownloadManager {
20382032 @JsonProperty(" ep" ) val ep : DownloadEpisodeMetadata ,
20392033 @JsonProperty(" links" ) val links : List <ExtractorLink >
20402034 )
2041- }
2035+ }
0 commit comments