@@ -338,12 +338,14 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
338338 break
339339 }
340340 httpConn!! .connect()
341- val contentType: String
341+ val contentType: String?
342342 if ((responseCode == HttpURLConnection .HTTP_OK || isResume && responseCode == HttpURLConnection .HTTP_PARTIAL ) && ! isStopped) {
343343 contentType = httpConn.contentType
344344 val contentLength: Long =
345345 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+ }
347349 log(" Content-Length = $contentLength " )
348350 val charset = getCharsetFromContentType(contentType)
349351 log(" Charset = $charset " )
@@ -517,7 +519,7 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
517519 * Create a file inside the Download folder using MediaStore API
518520 */
519521 @RequiresApi(Build .VERSION_CODES .Q )
520- private fun createFileInPublicDownloadsDir (filename : String? , mimeType : String ): Uri ? {
522+ private fun createFileInPublicDownloadsDir (filename : String? , mimeType : String? ): Uri ? {
521523 val collection: Uri = MediaStore .Downloads .EXTERNAL_CONTENT_URI
522524 val values = ContentValues ()
523525 values.put(MediaStore .Downloads .DISPLAY_NAME , filename)
@@ -770,7 +772,7 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
770772 return contentType?.split(" ;" )?.toTypedArray()?.get(0 )?.trim { it <= ' ' }
771773 }
772774
773- private fun isImageOrVideoFile (contentType : String ): Boolean {
775+ private fun isImageOrVideoFile (contentType : String? ): Boolean {
774776 val newContentType = getContentTypeWithoutCharset(contentType)
775777 return newContentType != null && (newContentType.startsWith(" image/" ) || newContentType.startsWith(" video" ))
776778 }
0 commit comments