Android webview input type file

后端 未结 3 983
走了就别回头了
走了就别回头了 2021-01-03 03:05

I\'m trying to build web project using android, from webview. I have a input field of type file to let user upload files to server,

3条回答
  •  迷失自我
    2021-01-03 03:43

    The answer by Riad points into the right direction, but that single callback is not enough to implement.

    There are, in total, four hidden API methods that you have to implement. Their usage depends on the Android version. These methods are:

    public void openFileChooser(ValueCallback uploadMsg)
    public void openFileChooser(ValueCallback uploadMsg, String acceptType)
    public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture)
    public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
    

    You can use the following library which does all these things for you:

    https://github.com/delight-im/Android-AdvancedWebView

    Alternatively, you may take a look at the source code to see how it's done:

    https://github.com/delight-im/Android-AdvancedWebView/blob/master/Source/src/im/delight/android/webview/AdvancedWebView.java

提交回复
热议问题