Android 4.4 WebView 文件选择器打不开? [英] Android 4.4 WebView file chooser not opening?

查看:26
本文介绍了Android 4.4 WebView 文件选择器打不开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在创建一个使用 webview 的应用程序,它将访问用户需要上传文件的页面.我们在 Android 4.4 中遇到问题,文件选择器无法打开,单击上传按钮不会发生任何事情.此功能适用于使用 openFileChooser 方法的早期版本,如下所示:

We are creating an app which uses the webview and will access a page where the user needs to upload a file. We are experiencing problems with Android 4.4 where the file chooser does not open and clicking the upload button causes nothing to happen. This functionality works with earlier versions using the openFileChooser method like so:

 webview.setWebChromeClient(new WebChromeClient() {
        //The undocumented magic method override
        //Eclipse will swear at you if you try to put @Override here
        // For Android 3.0+
        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
        }

        // For Android 3.0+
        public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("*/*");
            MainActivity.this.startActivityForResult(
                    Intent.createChooser(i, "File Browser"),
                    FILECHOOSER_RESULTCODE);
        }

        //For Android 4.1
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), MainActivity.FILECHOOSER_RESULTCODE);
        }

    });

我花了很多时间寻找在 4.4 上执行此操作的方法,但没有成功.有没有人设法做到这一点?

I have spent a good amount of time searching for a way to do it on 4.4 but have had no luck. Has anyone managed to do this?

推荐答案

WebView 按预期工作

如果我正确理解上述链接的意思,您(我和可能还有数百名开发人员)正在寻找黑客

If I understand correctly what the above link says , you (me and probably some hundreds more developers) are looking for a hack

这篇关于Android 4.4 WebView 文件选择器打不开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆