A WebView setting which enable JavaScript ,DomStorage and file access. - Android User Interface

Android examples for User Interface:WebView Javascript

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   w  w w  .j  a  v a  2 s  .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