我可以选择视频和图片,但无法在我的 webview
、kotlin
程序中上传。
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/