I have been struggling to upload files from WebView since last few days and there is no progress. I googled and implemented all suggested solutions but none works, like: solutions suggested here, and so on.
Problem: I have a HTML page with the following code to upload a file. It works fine in a desktop browser like Firefox and built-in browser of emulator / AVD i.e., when I click "Browse..." button rendered by element, browser opens a Dialog box where I can choose a file to upload.
However, in the android 3.0 emulator / AVD, when I click on "Choose file", nothing happens, no file dialog is opened!!!
<form method="POST" enctype="multipart/form-data">
File to upload: <input type="file" name="uploadfile">
<input type="submit" value="Press to Upload..."> to upload the file!
</form>
Could anyone please suggest a possible solution at the earliest.
This solution also works for Honeycomb and Ice Cream Sandwich. Seems like Google introduced a cool new feature (accept attribute) and forgot to to implement an overload for backwards compatibility.
Ive actually managed to get the file picker to appear in Kitkat, to select a image and to get the filepath in activity result but the only thing that im not able to "fix" (cause this workaround) is to make the input filed to fill out with file data.
Does anyone know any way how to access the input-field from a activity ? Am using this example comment. Is just this last piece, the last brick in the wall that i just have to put into right place (tho i could trigger upload of image file directly from code.
UPDATE #1
Im no hardcore Android dev so i'll show code on newbie level. Im creating a new Activity in already existing Activity
Manifest part
Am creating my BrowseActivity class from this example answer. The WebChromeClient() instance basically looks the same, except last piece, triggering the picker UI part...
And some more stuff
}
Lastly, some more code to get the actual file path, code found on SO, ive added post url in comments as well so the author gets credits for his work.
Lastly, the HTML page needs to trigger that new method of showPicker (specificaly when on A4.4)
Kotlin solution for Android 8:
Constants:
WebView setup:
And the onAcrtivityResult part:
Please, pay attention that our intent variable called "data".
In KitKat you can use the Storage Access Framework.
Storage Access Framework / Writing a Client App
This is work for me. Also work for Nougat and Marshmallow[[