的WebView Android 4.0的文件上传文件上传、WebView、Android

2023-09-05 00:26:04 作者:痴情丶又闷骚

这只是不工作。

我这样做

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);
        }
    });

但openFileChooser永远不会被调用。 有任何想法吗? openFileChooser标记@hide在Android源$ C ​​$ C。 我认为它的,因为你不应该使用这种方法。是否有其他方式来打开文件选择器??

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??

推荐答案

参数已经更新了一些时间。

Parameters for openFileChooser have been updated some times.

有关的Andr​​oid 3.0 - 4.0,这是

For Android 3.0 - 4.0, it is

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

4.1,

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

和2.X

public void openFileChooser( ValueCallback<Uri> uploadMsg )

您必须添加所有的人都支持Android 2.0和4.1之间的任何设备。

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