0

In my app Webview webpage file upload not working.but in mobile chrome browser it working. what will I need to do for file upload selector working

Here my Code

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

web.loadUrl(web_url);

In Chrome Browser I click File Selector shows this options

here image reference
enter image description here

How to add this options in my webview
Thanks for help

Venki WAR
  • 1,997
  • 4
  • 25
  • 38

1 Answers1

1

Use this,//we do open selector window for the URLs having "google" in the URI, you can change that :

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

            });

Change action name accordingly e.d. ACTION_SHARE

Gaurav Bansal
  • 604
  • 5
  • 11