@@ -338,12 +338,14 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
338
338
break
339
339
}
340
340
httpConn!! .connect()
341
- val contentType: String
341
+ val contentType: String?
342
342
if ((responseCode == HttpURLConnection .HTTP_OK || isResume && responseCode == HttpURLConnection .HTTP_PARTIAL ) && ! isStopped) {
343
343
contentType = httpConn.contentType
344
344
val contentLength: Long =
345
345
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) httpConn.contentLengthLong else httpConn.contentLength.toLong()
346
- log(" Content-Type = $contentType " )
346
+ if (contentType != null ) {
347
+ log(" Content-Type = $contentType " )
348
+ }
347
349
log(" Content-Length = $contentLength " )
348
350
val charset = getCharsetFromContentType(contentType)
349
351
log(" Charset = $charset " )
@@ -517,7 +519,7 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
517
519
* Create a file inside the Download folder using MediaStore API
518
520
*/
519
521
@RequiresApi(Build .VERSION_CODES .Q )
520
- private fun createFileInPublicDownloadsDir (filename : String? , mimeType : String ): Uri ? {
522
+ private fun createFileInPublicDownloadsDir (filename : String? , mimeType : String? ): Uri ? {
521
523
val collection: Uri = MediaStore .Downloads .EXTERNAL_CONTENT_URI
522
524
val values = ContentValues ()
523
525
values.put(MediaStore .Downloads .DISPLAY_NAME , filename)
@@ -770,7 +772,7 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
770
772
return contentType?.split(" ;" )?.toTypedArray()?.get(0 )?.trim { it <= ' ' }
771
773
}
772
774
773
- private fun isImageOrVideoFile (contentType : String ): Boolean {
775
+ private fun isImageOrVideoFile (contentType : String? ): Boolean {
774
776
val newContentType = getContentTypeWithoutCharset(contentType)
775
777
return newContentType != null && (newContentType.startsWith(" image/" ) || newContentType.startsWith(" video" ))
776
778
}
0 commit comments