A WebView setting which enable JavaScript ,DomStorage and file access - Android android.webkit

Android examples for android.webkit:WebView

Description

A WebView setting which enable JavaScript ,DomStorage and file access

Demo Code

import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Main{

    /**//from  www  . j a va2s.  c  o  m
     * A WebView setting which enable JavaScript ,DomStorage and file access.
     *
     * @param webView     The webView you wanna enable JavaScript
     * @param appCacheDir A String path to the directory containing Application Caches files.
     * @return The WebSettings instance
     */
    public static WebSettings enableJavaScript(WebView webView,
            String appCacheDir) {
        WebSettings webViewSettings = webView.getSettings();
        // wSet.setAppCacheMaxSize();
        webViewSettings.setJavaScriptEnabled(true);
        webViewSettings.setDomStorageEnabled(true);
        // String appCacheDir = this.getActivity().getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
        webViewSettings.setAppCachePath(appCacheDir);
        webViewSettings.setAllowFileAccess(true);
        webViewSettings.setAppCacheEnabled(true);
        webView.setWebViewClient(new webViewClient());
        webViewSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        return webViewSettings;
    }

}

Related Tutorials