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.
I found it necessary to define
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
, in Android 4.1. Then I followed Michel Olivier's solution.I found that I needed 3 interface definitions in order to handle various version of android.
hifarrer's full solution is very helpful to me.
but, I met many other problems - supporting other mime type, listing capture devices(camera, video, audio recoder), opening capture device immediately(ex: <input accept="image/*;capture"> )...
So, I made a solution that works exactly same as default web browser app.
I used android-4.4.3_r1/src/com/android/browser/UploadHandler.java. (thanks to Rupert Rawnsley )
additional string resoruce of res/values/string.xml :
If you are using proguard, you may need below option in proguard-project.txt :
UPDATE #1 (2015.09.09)
adds code for Android 5.0.1 compatability.
I'm new to Andriod and struggled with this also. According to Google Reference Guide WebView.
Example code I executed in MainActvity.java.
Excuted
have you visited this links? http://groups.google.com/group/android-developers/browse_thread/thread/dcaf8b2fdd8a90c4/62d5e2ffef31ebdb
http://moazzam-khan.com/blog/?tag=android-upload-file
http://evgenyg.wordpress.com/2010/05/01/uploading-files-multipart-post-apache/
Concise example of file upload via Java lib Apache Commons
i think you will get help from this
Google's own browser offers such a comprehensive solution to this problem that it warrants it's own class:
openFileChooser implementation in Android 4.0.4
UploadHandler class in Android 4.0.4