JavaScript not working in Android Webview?

I'm trying to make an Android version of a relativly simple iOS app that uses a webview, some buttons and then relies on javascript calls to a CMS.

But I'm stuck at a pretty early point of development: The webview doesn't function with javascript.I've read a lot of posts about how to enable JS in an Android webview, but no luck so far.

Below is some of my code:

public void onCreate(Bundle savedInstanceState) {

    mWebView = (WebView) findViewById(;
    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.setWebViewClient(new HelloWebViewClient()
        public void onPageFinished(WebView view, String url)  
            //Calling an init method that tells the website, we're ready 

private class HelloWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return true;


public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
        return true;
    return super.onKeyDown(keyCode, event);

public void page11(View view)

What am I doing wrong here? The URL is working perfectly in my iOS app, and in a browser. But not in my app!

Please tell me it's something obvious...

FIXED! Spurred on by the error, I found out that I needed to set


for the webview settings.

Thanks for your help Stephan :)

In case something with WebView on Android does not work, I always try to make sure I set these crazy flags such as,

    WebSettings webSettings = webView.getSettings();

I wonder why these are not set by Default, who would expect webpages without javascript content nowadays, and whats the use having javascript enabled when DOM is unavailable unless specified. Hope someone filed this as a bug or improvement/feature-request already and the monkeys are working on it.

and then there is deprecated stuff rotting somewhere, like this:


All this for loading webpages inside app.

On iOS, its all so simple - Swift 3.0

private func openURLWithInAppBrowser(urlString:String) {
    guard let url = URL(string:urlString) else {
    let sfSafari = SFSafariViewController(url:url)
    present(sfSafari, animated: true, completion: nil)

Loading javascript in webview


Did you enable the right internet permission in the manifest? Everything looks fine otherwise. By any chance, have you also tested this code on an actual Android phone? And not just on the emulator?

Here is a good tutorial on a slightly different approach. You may want to try that one to see if it works for you.

Add the following lines of code in your

It helped me to enable js

  webView.setWebChromeClient(new WebChromeClient());
  webView.setWebViewClient(new WebViewClient());

do not forget about this permission in AndroidManifest file.

<uses-permission Android:name="Android.permission.INTERNET" />

This video ( gave me the hint to make it work. The key is to save your html and js files in the Android assets/ folder. Then you can easily access them via:


Just permit your WebView to run JS, simple like that:

WebView web=(WebView)findViewById(;

To enable javascript popups in WebView its necessary to set webChromeClient and override openFileChooser methods.

    mWebview.setWebChromeClient(new WebChromeClient(){
        // For Android 4.1+
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            mUploadMessage = uploadMsg;

            Intent i = new Intent(Intent.ACTION_GET_CONTENT);


            startActivityForResult(Intent.createChooser(i, "SELECT"), 100);

        // For Android 5.0+
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
            if (mUploadMessageArr != null) {
                mUploadMessageArr = null;

            mUploadMessageArr = filePathCallback;

            Intent intent = fileChooserParams.createIntent();

            try {
                startActivityForResult(intent, 101);
            } catch (ActivityNotFoundException e) {
                mUploadMessageArr = null;

                Toast.makeText(activity,"Some error occurred.", Toast.LENGTH_LONG).show();

                return false;

            return true;

And handle the onActivityResult as below:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 100) {
        if (mUploadMessage == null) return;
        Uri result = data == null || resultCode != Activity.RESULT_OK ? null : data.getData();
        mUploadMessage = null;

    else if (requestCode == 101) {
        if (mUploadMessageArr == null) return;
        mUploadMessageArr.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, data));
        mUploadMessageArr = null;


If nothing above helped try to add delay in WebViewClient.onPageFinished listener

override fun onPageFinished(view: WebView?, url: String?) {
                //update your view with js here
                super.onPageFinished(view, url)
            }, 1000)

If you are in Kotlin you can use the following method to get the JavaScript working :

webView.apply {

     settings.javaScriptEnabled = true
     settings.domStorageEnabled = true

Also make sure that your entire folder is inside the Assets folder (this includes HTML, Javascript and other file needed)

Xamarin Android also has the same problem that WebView does not execute any Javascript. Follow @computingfreak answer:


        var webView = this.FindViewById<WebView>(Resource.Id.webView);

        var webSettings = webView.Settings;
        webSettings.JavaScriptEnabled = true;
        webSettings.DomStorageEnabled = true;
        webSettings.LoadWithOverviewMode = true;
        webSettings.UseWideViewPort = true;
        webSettings.BuiltInZoomControls = true;
        webSettings.DisplayZoomControls = false;
        webSettings.DefaultTextEncodingName = "utf-8";

Weirdly enough they changed all setter methods to properties except SetSupportZoom and SupportZoom stays as getter :/

Mainly, these three lines will be enough to make the Javascipt work in webView...

webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());

If it's not working after that also, then add below line also.


Actually, you need both setJavaScriptEnabled() and setWebChromeClient(new WebChromeClient()) to make the JavaScript work. If you will use only webSetting.setJavaScriptEnabled(true); then it won't work.