【问题标题】:Android-Webview webpage File-Upload selector not workingAndroid-Webview 网页文件上传选择器不起作用
【发布时间】:2018-06-08 14:33:33
【问题描述】:

在我的应用程序Webview 网页文件上传不起作用。但在移动 chrome 浏览器中它可以工作。我需要做什么才能使文件上传选择器正常工作

这是我的代码

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

web.loadUrl(web_url);

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

这里图片参考

如何在我的webview中添加此选项
感谢您的帮助

【问题讨论】:

  • 你设置权限了吗?
  • 我需要什么样的权限
  • 我没有设置这个权限
  • 那么你将如何获得文件访问权限?

标签: android


【解决方案1】:

使用这个,//我们会为 URI 中带有“google”的 URL 打开选择器窗口,您可以更改它:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-08-07
    • 2022-06-16
    • 1970-01-01
    相关资源
    最近更新 更多