Android-Webview网页文件上传选择器不起作用

时间:2018-06-08 05:49:46

标签: android

在我的应用Webview网页文件上传无效。但在移动Chrome浏览器中,它正常运行。我需要做什么才能使文件上传选择器正常工作

这是我的代码

WebView web = findViewById(R.id.webview);
WebSettings websetting = web.getSettings();
websetting.setJavaScriptEnabled(true);

web.loadUrl(web_url);

在Chrome浏览器中,我点击文件选择器显示此选项

这里图像参考
enter image description here

如何在webview中添加此选项 谢谢你的帮助

1 个答案:

答案 0 :(得分:1)

使用此功能,//我们为URI中包含“google”的网址打开选择器窗口,您可以更改:

webView.setWebViewClient(new WebViewClient() {      
                ProgressDialog progressDialog;

                //If you will not use this method url links are open in new brower not in webview
                public boolean shouldOverrideUrlLoading(WebView view, String url) {              

                    // Check if Url contains ExternalLinks string in url 
                    // then open url in new browser
                    // else all webview links will open in webview browser
                    if(url.contains("google")){ 

                        // Could be cleverer and use a regex
                        //Open links in new browser
                        view.getContext().startActivity(
                                new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

                        // Here we can open new activity

                        return true;

                    } else {

                        // Stay within this webview and load url
                        view.loadUrl(url); 
                        return true;
                    }

                }



                //Show loader on url load
                public void onLoadResource (WebView view, String url) {

                    // if url contains string androidexample
                    // Then show progress  Dialog
                    if (progressDialog == null && url.contains("androidexample") 
                            ) {

                        // in standard case YourActivity.this
                        progressDialog = new ProgressDialog(ShowWebView.this);
                        progressDialog.setMessage("Loading...");
                        progressDialog.show();
                    }
                }

                // Called when all page resources loaded
                public void onPageFinished(WebView view, String url) {

                    try{
                        // Close progressDialog
                        if (progressDialog.isShowing()) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                    }catch(Exception exception){
                        exception.printStackTrace();
                    }
                }

            });

相应地更改行动名称e.d. ACTION_SHARE