I am downloading pdf files inside web view in android studio. That's going well. I am successfully downloading a pdf file with the .pdf extension but when I click on the file see a toast message something went wrong can't open this file Here is my code
binding?.webView?.setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
val pdfUrl:String = url.trim().replace("blob:","")
Log.e(TAG, "loadWAWeb: $pdfUrl")
if (storagePermission()) {
// binding?.webView?.loadUrl(JavaScriptInterface.getBase64StringFromBlobUrl(url,mimetype))
val request = DownloadManager.Request(Uri.parse(pdfUrl))
request.setMimeType(mimetype)
request.allowScanningByMediaScanner()
request.setDescription("Downloading file...")
val fileName = URLUtil.guessFileName(pdfUrl, contentDisposition, mimetype)
request.setTitle(fileName)
Log.e(TAG, "loadWAWeb: $fileName" )
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
val dm = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
dm.enqueue(request)
}
}
this is a pdf file which is good in format but I don't know where is the issue.
but when I try to open this file. This issue that I am facing.


I Don't see that have a problem, maybe the pdf file just corrupted. Test in another PDF File or just update your Android Studio. in my case before i am implement Fast Android Networking the file sometimes corrupted, but after i am implement Fast Android Networking the file is not corrupted.
in Gradle, paste this
and add Internet Permission on Manifest.xml
Then initialize it in onCreate() Method of application class
i think my explanation is not that good, you can see at https://github.com/amitshekhariitbhu/Fast-Android-Networking
im sorry if this not make you problem solved, but based on my case it solved