文件选择对话框中的Andr​​oid的WebView不开放,如果"显示:无" [英] File chooser dialog not opening in android webview if "display:none"

查看:260
本文介绍了文件选择对话框中的Andr​​oid的WebView不开放,如果"显示:无"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好开发商

好吧,我取得了一个Android的WebView应用程序,我米面临的一个小问题,我搜索了很多,但也没有发现任何有效的解决方案。

Well I have made an android webview application, I m facing a little issue, I searched alot but couldn't found any valid solution.

确定。问题是,。我有一个PHP / HTML code这样的

Ok. the problem is that. I have a php/Html code like this

 <input type="file" name="banner_image" style="display:none;" id="banner_image" onChange="fileSelected('banner');" accept="image/*" />

注意:的的风格=显示:无;

我打电话是输入字段的的 DIV 的onClick通过jQuery这样的onclick事件

I m calling the onclick event of input field from onClick of a div via Jquery like this

<div class="profile-pic-txt" onClick="openFileDialog('profile');"> Click here to add
        Profile Picture
        <p>200px/200px</p>
      </div>

和这里是我的Java脚本打开文件对话框()函数

and here is my java-script openFileDialog() function

function openFileDialog(test)
{
$("#banner_image").click();
console.log("Test");
}

它不是我打开文件选择对话框。

Its not opening my file chooser dialog.

但是,当我删除此显示:无;从我上面的$ C $ ç它只是工作的罚款。我的iPhone在这两个条件,但在Android的WebView中测试了这个它的做工精细它不是我的调用文件选择对话框中,同时保持显示:无

But when i remove this display:none; from my above code its just working fine. I tested this in iPhone its working fine in both conditions but in android webview its not invoking my file chooser dialog while keeping display:none.


我必须让我的浏览按钮,从我的网页作为模板/设计要求不可见的(我已经有显示完成:无

和过去这里是我的Andr​​oid的WebView配置code。

and in the last here is my android webview configuration code.

private void configureWebview() {

    webView.getSettings().setDefaultZoom(ZoomDensity.FAR);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setCacheMode(MODE_APPEND);
    webView.getSettings().setUseWideViewPort(true);

    webView.getSettings().setRenderPriority(RenderPriority.HIGH);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    webView.setWebViewClient(new MyWebViewClient());

    webView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {

            Log.e("Console Webview",
                    cm.message() + " -- From line " + cm.lineNumber()
                            + " of " + cm.sourceId());

            return true;

        }

        // For Android < 3.0
        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            uploadMessage = 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+
        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg,
                String acceptType) {
            uploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            MainActivity.this.startActivityForResult(
                    Intent.createChooser(i, "File Browser"),
                    FILECHOOSER_RESULTCODE);
        }

        // For Android 4.1
        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg,
                String acceptType, String capture) {
            uploadMessage = 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);
        }

    });

}

只是在重复我的问题:无在&LT;输入名称=banner_image的风格=显示:同时保持显示文件选择器不开放:没有; ID =banner_image的onChange =fileSelected('旗帜');类型=文件接受=图像/ */&GT;

推荐答案

如果您使用的输入文件不起作用显示:无

input file doesn't work if you use display:none

只是把它的可视区域之外,例如使用的位置是:绝对的;左:-500px;

just put it outside the viewable area, for example with position: absolute;left: -500px;

这篇关于文件选择对话框中的Andr​​oid的WebView不开放,如果&QUOT;显示:无&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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