Android的web视图,文件输入字段文件选择器不显示文件、字段、视图、选择器

2023-09-06 03:28:14 作者:听说我们分手了╰+

我应该在一个应用程序中的web视图显示网页。该页面包含HTML表单,其中的一个字段是文件。因此,它是这样...

I am supposed to display a web page in a webview in an app. The page contains a html form where one of the fields is file. So it goes something like...

<input type="file" name="file">

如果我在浏览器和preSS打开的页面中选择文件按钮,文件选择弹出,一切都很好,但是当我preSS在web视图没有选择文件按钮发生了:/

If I open the page in the browser and press the Choose File button, file chooser pops up and everything is good, but when I press the Choose File button in the webview nothing happens :/

任何想法如何使这项工作?

Any ideas how to make this work?

推荐答案

WebView功能在默认情况下没有打开文件选择。但是,可以使这项工作。 WebChromeClient 已隐藏方法 openFileChooser ,这需要重写,弹出文件选择,然后返回结果的WebView 。据大师一个人永远不能使用Android SDK中的隐藏方法,所以这不是一个很好的解决方案,而且很可能不应该在企业应用中使用。但是Android的股票浏览器不正是这样。一些信息我如何推翻这个方法是我这个question.如果有人需要源让我知道生病后它的地方。

WebView by default doesn't open file chooser. However it is possible to make this work. WebChromeClient has hidden method openFileChooser, which needs to be overridden to pop up a file chooser and then return the result to WebView. According to gurus one should never use hidden methods of Android SDK so this is not a good solution, and probably shouldn't be used in enterprise apps. However Android's stock Browser does exactly this way. Little more information how I overrode this method is in my this question. If anyone needs the source let me know Ill post it somewhere.