0

Ok, I will try to ask this again with more details. (Please don't answer with links because I've probably visited all related sites but non works for me.)

I need to achieve 3 things in a WebView:

  1. Disable zoom
  2. Hide URL
  3. Upload files from mobile device

I have a URL that points to a phpbb where users can upload an avatar.

Now this is what I can do:

  1. Disable zoom
    • Works with WebViewClient
  2. Hide URL
    • Works with WebViewClient
  3. Upload files from mobile device
    • Works with WebChromeClient

I can achieve 1 and 2 with WebViewClient. I can achieve 3 with WebChromeClient.

Can I use both WebViewClient and WebChromeClient where WebChromeClient is used to only handle the file upload? (the upload button comes from phpbb site)

Edit (code added)

        wv = (WebView) findViewById(R.id.webViewForum);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.loadUrl(websiteForum);
        wv.getSettings().setSupportZoom(false);
        wv.getSettings().setBuiltInZoomControls(false);

        wv.setWebViewClient(new MyWebViewClient());
        wv.setWebChromeClient(new MyWebChromeClient());

}

public class MyWebChromeClient extends WebChromeClient {
    //Handle javascript alerts:
    @Override
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)  
{
  Log.d("alert", message);
  Toast.makeText(getBaseContext(), message, 3000).show();
  result.confirm();
  return true;
}
};

public class MyWebViewClient extends WebViewClient {
    @Override
        //Run script on every page, similar to Greasemonkey:
    public void onPageFinished(WebView view, String url) {
            view.loadUrl("javascript:alert('hi')");
        }
}

Please see screenshot below, when I click on choose file nothing happens:

Choose File

TwoStarII
  • 351
  • 3
  • 17
  • 1
    Based upon [your previous question](https://stackoverflow.com/questions/29879655/hide-url-in-webchromeclient), you seem to think that `shouldOverrideUrlLoading()` "hides" a URL. `shouldOverrideUrlLoading()` is invoked when users click on links or when servers issue HTTP redirect responses (e.g., 301). The default behavior of `WebView` is to launch those URLs in the user's default Web browser. The user's default Web browser *is not your app*. Your `shouldOverrideUrlLoading()` keeps the user within your app (for link clicks and HTTP redirections), by loading those URLs back in the `WebView`. – CommonsWare Apr 26 '15 at 19:22
  • @CommonsWare so how to I let WebChromeClient handle file uploads? – TwoStarII Apr 27 '15 at 05:11
  • Use whatever you used for bullet #3 in your list. You indicated that you had that working. – CommonsWare Apr 27 '15 at 10:34
  • @CommonsWare - If I use WebChromeClient I loose 1 and 2. If I use WebViewClient I loose 3. I can't use both, if I try and use both it always takes WebViewClient and ignores WebChromeClient. – TwoStarII Apr 27 '15 at 14:03
  • 48 people agree with the accepted answer on the duplicate question (the person who wrote the answer, plus 47 upvotes). You are going to need to prove your claims that this does not work, such as publishing a sample app that demonstrates that it does not work. – CommonsWare Apr 27 '15 at 14:12
  • @CommonsWare - Ok here's what the app does, WebViewClient uses "choose file"(which cannot browse files) and WebChromeClient uses "browse file" (which works). I'll look at the duplicate question for the 10th time and hopefully I'll pick something up – TwoStarII Apr 27 '15 at 14:56
  • @CommonsWare - I tried the code from the duplicate question, doesn't work. I posted code and screenshot from an edit from my question. – TwoStarII Apr 27 '15 at 15:29
  • I have no idea why you would expect anything in your Java code to be reacting based upon tapping the "Choose File" button. Also, `` has been broken since 4.4. See https://code.google.com/p/android/issues/detail?id=62220. Beyond that, please configure your `WebView` fully before calling `loadUrl()`. – CommonsWare Apr 27 '15 at 15:38
  • @ CommonsWare - ok I just tested on a Sony Android 4.4.4 device and this works, I tried using same code on Samsung Android 4.4.2 AND 5.0.1 and it doesn't work, now I have no idea except to say it is version or hardware related? – TwoStarII May 07 '15 at 14:00

0 Answers0