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:
- Disable zoom
- Hide URL
- 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:
- Disable zoom
- Works with WebViewClient
- Hide URL
- Works with WebViewClient
- 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: