Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView Android 4.0 file upload

It's just NOT working.

I'm doing this

webView.setWebChromeClient(new WebChromeClient() {

        public void openFileChooser(ValueCallback<Uri> uploadFile) {
            System.out.println("openFileChooser");
            mUploadMessage = uploadFile;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("file/*");
            PresentationActivity.this.startActivityForResult(
                    Intent.createChooser(i, "Image Browser"),
                    FILECHOOSER_RESULTCODE);
        }
    });

but openFileChooser is never called. Any ideas? openFileChooser is marked @hide in Android source code. I think its because you should NOT use this method. Is there another possibility to open a fileChooser??

like image 218
Basic Coder Avatar asked Jun 08 '12 18:06

Basic Coder


1 Answers

Parameters for openFileChooser have been updated some times.

For Android 3.0 - 4.0, it is

public void openFileChooser( ValueCallback<Uri> uploadMsg, String acceptType )

for 4.1,

public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)

and for 2.x

public void openFileChooser( ValueCallback<Uri> uploadMsg )

You'll have to add all of them to support any devices between Android 2.0 and 4.1.

like image 102
Fujix Avatar answered Nov 15 '22 01:11

Fujix