android - 我无法在 kotlin webview 中上传图片、视频和文件

标签 android file-upload webview kotlin image-upload

我可以选择视频和图片,但无法在我的 webviewkotlin 程序中上传。

webview.setWebChromeClient(object:WebChromeClient() {
                override fun onShowFileChooser(webView:WebView, filePathCallback:ValueCallback<Array<Uri>>, fileChooserParams:FileChooserParams):Boolean {
                    var mFilePathCallback = filePathCallback
                    val intent = Intent(Intent.ACTION_GET_CONTENT)
                    intent.setType("*/*")
                    val PICKFILE_REQUEST_CODE = 100
                    startActivityForResult(intent, PICKFILE_REQUEST_CODE)
                    return true
                }
            })

            fun onActivityResult(requestCode: Int, resultCode: Int,
                                 intent: Intent,
                                 mFilePathCallback: Any): Boolean {
                var PICKFILE_REQUEST_CODE = null
                if (requestCode == PICKFILE_REQUEST_CODE)
                {
                    val result = if (intent == null || resultCode != RESULT_OK)
                        null
                    else
                        intent.getData()
                    val resultsArray = arrayOfNulls<Uri>(1)
                    resultsArray[0] = result
                    mFilePathCallback.onReceiveValue(resultsArray)

                }
                return true
            }

最佳答案

你需要添加到你的@Override onActivityResult

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
  if (requestCode == REQUEST_SELECT_FILE) {
        if (null == uploadMessage) {
            return
        }
        uploadMessage?.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode,data))
        uploadMessage = null

    }
}

但不在您的“webview.setWebChromeClient(object:WebChromeClient()”) 内部,他不会覆盖。

关于android - 我无法在 kotlin webview 中上传图片、视频和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49167572/

相关文章:

安卓 : stop and play sound on button click

android - 如何在打瞌睡模式(Nougat)下将系统应用程序列入白名单?

wordpress - 如何在前端将 Dropzonejs 与 wordpress 媒体处理程序集成?

ios - 有没有办法通过 Alamofire 上传 doc、pdf 文件?

android - FlipAnimation 在 4.4.3 中导致问题

android - 在 flutter elevatedbutton 中设置宽度

android - Kotlin 高阶函数如何工作?

asp.net - 在 ASP.net 中上传文件而不使用 FileUpload 服务器控件

java - Android WebView Word Wrapping 捏缩放文本内容

android - onPause - 尝试调用虚拟方法 WebView