Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将文件从webview下载到内部存储器_Android_Kotlin - Fatal编程技术网

Android 将文件从webview下载到内部存储器

Android 将文件从webview下载到内部存储器,android,kotlin,Android,Kotlin,下面的代码可以完美地将mp3文件下载到外部存储器中,但无法将文件下载到内部存储器中。很多智能手机都没有外部存储器。我能做什么?如果需要的话,我不知道如何在kotlin中实现异步任务 mywebView.setDownloadListener(object : DownloadListener { override fun onDownloadStart(url: String, userAgent: String,

下面的代码可以完美地将mp3文件下载到外部存储器中,但无法将文件下载到内部存储器中。很多智能手机都没有外部存储器。我能做什么?如果需要的话,我不知道如何在kotlin中实现异步任务

 mywebView.setDownloadListener(object : DownloadListener {
        override fun onDownloadStart(url: String, userAgent: String,
                                     contentDisposition: String, mimetype: String,
                                     contentLength: Long) {


            val request = DownloadManager.Request(Uri.parse(url))
            request.allowScanningByMediaScanner()
            request.setDescription("Download file...")
            request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype))

            request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) //Notify client once download is completed!
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mimetype )
            val webview = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
            webview.enqueue(request)

            Toast.makeText(getApplicationContext(), "Download avviato", Toast.LENGTH_LONG).show()

        }
    })

目前无法测试代码,但应该如下所示:

 mywebView.setDownloadListener(object : DownloadListener {
        override fun onDownloadStart(url: String, userAgent: String,
                                     contentDisposition: String, mimetype: String,
                                     contentLength: Long) {


            val request = DownloadManager.Request(Uri.parse(url))
            request.allowScanningByMediaScanner()
            request.setDescription("Download file...")
            request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype))

            request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) //Notify client once download is completed!
            request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory(), mimetype )
            val webview = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
            webview.enqueue(request)

            Toast.makeText(getApplicationContext(), "Download avviato", Toast.LENGTH_LONG).show()

        }
    })

读和读。因此,所有智能手机都有外部存储,而不是所有智能手机都有SD卡。他要求的是内部存储,而不是外部存储