Skip to content
Advertisement

Android Java Upload File via WebView without FileChooser

I need to write an Android application which is capable of loading a Website via a WebView. The Website contains an Input (Type=FILE)

JavaScript

When loading is done, the application should use a specific Image and upload it via a storage path:

JavaScript

I already tried to open a FileChooser-Dialog and that works, but I need a solution without the filechooser. The path of the “Path”-Variable should be used. I know that this would be a huge security leak, but is there maybe a solution for this? Maybe change die input-value via JavaScript? Maybe with a Library?

PS: Not meant to do anything illegal – the company app is generating profile images and they need to be uploaded via an existing unchangeable Input of type File.

Thanks in advance.

Advertisement

Answer

You can try this:

1) Get the URI of your file.


2) Trigger file chooser


3) Override onShowFileChooser inside WebChromeClient like this:

JavaScript

Here myURI is the URI of your file.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement