我有一个显示webView的应用程序。我终于可以上传输入内容了:
class MainActivity : AppCompatActivity() {
private lateinit var webWindow: WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
webWindow = findViewById(R.id.webView)
webWindow.settings.javaScriptEnabled = true
webWindow.loadUrl("http://8wr.io/scoreboard/")
webWindow.webViewClient = WebViewClient()
webWindow.webChromeClient = MyWebChromeClient()
}
private var mFilePathCallback: ValueCallback<Array<Uri>>? = null
private val FILECHOOSER_RESULTCODE = 1
internal inner class MyWebChromeClient : WebChromeClient() {
override fun onShowFileChooser(webView:WebView, filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams:FileChooserParams):Boolean {
mFilePathCallback = filePathCallback
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "image/*"
startActivityForResult(Intent.createChooser(intent, "Image Browser"), FILECHOOSER_RESULTCODE)
return true
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == FILECHOOSER_RESULTCODE) {
mFilePathCallback?.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode,data))
mFilePathCallback = null
}
}
}
但是,一次只能上传一个文件。我网站上的表格一次允许多个文件。如何更改文件选择器以正确处理多个文件?
我尝试添加:
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
但是,尽管这确实允许我选择多个文件,但是生成的表单没有选择多个文件。实际上最终什么也没收到。