Java Code Examples for com.tencent.smtt.sdk.WebSettings#setSaveFormData()

The following examples show how to use com.tencent.smtt.sdk.WebSettings#setSaveFormData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrapperWebView.java    From AndroidHybridLib with Apache License 2.0 6 votes vote down vote up
private void initWebViewSettings() {
    WebSettings ws = mWebView.getSettings();
    ws.setDefaultTextEncodingName("utf-8");
    ws.setJavaScriptEnabled(true);
    ws.setPluginsEnabled(true);
    ws.setDomStorageEnabled(true);
    ws.setRenderPriority(com.tencent.smtt.sdk.WebSettings.RenderPriority.HIGH);
    ws.setAllowFileAccess(true);
    ws.setAllowContentAccess(true);
    ws.setAppCacheEnabled(false);
    ws.setCacheMode(com.tencent.smtt.sdk.WebSettings.LOAD_NO_CACHE);
    ws.setSaveFormData(true);
    ws.setJavaScriptCanOpenWindowsAutomatically(true);
    ws.setLoadsImagesAutomatically(true);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        ws.setAllowFileAccessFromFileURLs(true);
        ws.setAllowUniversalAccessFromFileURLs(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        mWebView.setWebContentsDebuggingEnabled(true);
    }
}
 
Example 2
Source File: MyTestActivity.java    From AndroidFrame with Apache License 2.0 5 votes vote down vote up
private void initWebview() {

        InputStream fs = this.getResources().openRawResource(
                R.raw.jsbridge_init);
        jsbridgeInitScript = Util.getLocalText(fs);

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

        WebSettings webSettings = mWebview.getSettings();

        try {
            // setPageCacheCapacity(webSettings);
            webSettings.setSavePassword(false);//是否保存密码,api18已经过时
            webSettings.setSaveFormData(false);//是否保存表单数据
            webSettings.setJavaScriptEnabled(true);//允许JavaScript运行
            webSettings.setTextZoom(100);//设置网页文本缩放百分比,默认100
            webSettings.setDomStorageEnabled(true);//是否允许网页向本地存储数据
            webSettings.setAppCacheEnabled(true);//这是允许缓存,包括session数据和持久化数据
            String path = Environment.getExternalStorageDirectory() + "jsTest";
            webSettings.setAppCachePath(path);//设置缓存路径,与setAppCacheEnabled配合使用
            webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//先从网络获取,如果网络不可用则从本地获取
            String userAgent = webSettings.getUserAgentString();
            webSettings.setUserAgentString(userAgent);//可以自定义用户代理
        } catch (Exception e) {
            e.printStackTrace();
        }


        WebViewJavascriptBridge ylBridge = new WebViewJavascriptBridge(this, mHandler, mWebview);
        mWebview.addJavascriptInterface(ylBridge,
                "AndroidWebViewJavascriptBridge");

//        if (android.os.Build.VERSION.SDK_INT <= 18) {
        mWebview.loadUrl("file:///android_asset/jstest.html");
//        mWebview.loadUrl("https://www.baidu.com/");
//        } else {
//            mWebview.evaluateJavascript("https://www.baidu.com/", null);
//        }
    }
 
Example 3
Source File: WebViewFragment.java    From Dainty with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void setSettings(WebSettings setting) {
    //noinspection deprecation
    setting.setJavaScriptEnabled(true);
    setting.setJavaScriptCanOpenWindowsAutomatically(true);
    setting.setAllowFileAccess(true);
    setting.setSupportZoom(true);
    setting.setBuiltInZoomControls(true);   //允许放大缩小
    setting.setDisplayZoomControls(false);    //去掉放大缩小框
    setting.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    setting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    setting.setSupportMultipleWindows(false);

    setting.setGeolocationEnabled(true);   //允许启用地理定位
    setting.setGeolocationDatabasePath(getActivity().getDir("geolocation", 0).getPath());
    setting.setSaveFormData(true);  //支持保存自动填充的表单数据
    setting.setDomStorageEnabled(true);  //支持DOM缓存
    setting.setDatabaseEnabled(true);
    setting.setAppCacheEnabled(true);
    setting.setAppCacheMaxSize(Long.MAX_VALUE);
    setting.setAppCachePath(getActivity().getDir("dainty_cache", 0).getPath());

    // 全屏显示
    setting.setUseWideViewPort(true);
    setting.setTextZoom(Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getContext()).getString("text_size", "100")));

}
 
Example 4
Source File: X5WebView.java    From YCWebView with Apache License 2.0 4 votes vote down vote up
/**
 * 做一些公共的初始化操作
 */
private void initWebViewSettings() {
    WebSettings ws = this.getSettings();
    // 网页内容的宽度是否可大于WebView控件的宽度
    ws.setLoadWithOverviewMode(false);
    // 保存表单数据
    ws.setSaveFormData(true);
    // 是否应该支持使用其屏幕缩放控件和手势缩放
    ws.setSupportZoom(true);
    // 设置内置的缩放控件。若为false,则该WebView不可缩放
    ws.setBuiltInZoomControls(true);
    // 隐藏原生的缩放控件
    ws.setDisplayZoomControls(false);
    // 启动应用缓存
    ws.setAppCacheEnabled(true);
    // 设置缓存模式
    // 缓存模式如下:
    // LOAD_CACHE_ONLY: 不使用网络,只读取本地缓存数据
    // LOAD_DEFAULT: (默认)根据cache-control决定是否从网络上取数据。
    // LOAD_NO_CACHE: 不使用缓存,只从网络获取数据.
    // LOAD_CACHE_ELSE_NETWORK,只要本地有,无论是否过期,或者no-cache,都使用缓存中的数据。
    ws.setCacheMode(WebSettings.LOAD_DEFAULT);
    ws.setAppCacheMaxSize(Long.MAX_VALUE);
    // setDefaultZoom  api19被弃用
    // 设置此属性,可任意比例缩放。
    ws.setUseWideViewPort(true);
    // 告诉WebView启用JavaScript执行。默认的是false。
    // 注意:这个很重要   如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
    ws.setJavaScriptEnabled(true);
    //  页面加载好以后,再放开图片
    //ws.setBlockNetworkImage(false);
    // 使用localStorage则必须打开
    ws.setDomStorageEnabled(true);
    //防止中文乱码
    ws.setDefaultTextEncodingName("UTF-8");
    /*
     * 排版适应屏幕
     * 用WebView显示图片,可使用这个参数
     * 设置网页布局类型: 1、LayoutAlgorithm.NARROW_COLUMNS :
     * 适应内容大小 2、LayoutAlgorithm.SINGLE_COLUMN:适应屏幕,内容将自动缩放
     */
    ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    // WebView是否新窗口打开(加了后可能打不开网页)
    //ws.setSupportMultipleWindows(true);
    // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ws.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
    //设置字体默认缩放大小
    ws.setTextZoom(100);
    // 不缩放
    this.setInitialScale(100);
    if(Build.VERSION.SDK_INT >= KITKAT) {
        //设置网页在加载的时候暂时不加载图片
        ws.setLoadsImagesAutomatically(true);
    } else {
        ws.setLoadsImagesAutomatically(false);
    }
    //默认关闭硬件加速
    setOpenLayerType(false);
    //默认不开启密码保存功能
    setSavePassword(false);
    //移除高危风险js监听
    setRemoveJavascriptInterface();
}
 
Example 5
Source File: X5WvWebView.java    From YCWebView with Apache License 2.0 4 votes vote down vote up
/**
 * 做一些公共的初始化操作
 */
private void initWebViewSettings() {
    WebSettings ws = this.getSettings();
    // 网页内容的宽度是否可大于WebView控件的宽度
    ws.setLoadWithOverviewMode(false);
    // 保存表单数据
    ws.setSaveFormData(true);
    // 是否应该支持使用其屏幕缩放控件和手势缩放
    ws.setSupportZoom(true);
    // 设置内置的缩放控件。若为false,则该WebView不可缩放
    ws.setBuiltInZoomControls(true);
    // 隐藏原生的缩放控件
    ws.setDisplayZoomControls(false);
    // 启动应用缓存
    ws.setAppCacheEnabled(true);
    // 设置缓存模式
    // 缓存模式如下:
    // LOAD_CACHE_ONLY: 不使用网络,只读取本地缓存数据
    // LOAD_DEFAULT: (默认)根据cache-control决定是否从网络上取数据。
    // LOAD_NO_CACHE: 不使用缓存,只从网络获取数据.
    // LOAD_CACHE_ELSE_NETWORK,只要本地有,无论是否过期,或者no-cache,都使用缓存中的数据。
    ws.setCacheMode(WebSettings.LOAD_DEFAULT);
    ws.setAppCacheMaxSize(Long.MAX_VALUE);
    // setDefaultZoom  api19被弃用
    // 设置此属性,可任意比例缩放。
    ws.setUseWideViewPort(true);
    // 告诉WebView启用JavaScript执行。默认的是false。
    // 注意:这个很重要   如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
    ws.setJavaScriptEnabled(true);
    //  页面加载好以后,再放开图片
    //ws.setBlockNetworkImage(false);
    // 使用localStorage则必须打开
    ws.setDomStorageEnabled(true);
    //防止中文乱码
    ws.setDefaultTextEncodingName("UTF -8");
    /*
     * 排版适应屏幕
     * 用WebView显示图片,可使用这个参数
     * 设置网页布局类型: 1、LayoutAlgorithm.NARROW_COLUMNS :
     * 适应内容大小 2、LayoutAlgorithm.SINGLE_COLUMN:适应屏幕,内容将自动缩放
     */
    ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    // WebView是否新窗口打开(加了后可能打不开网页)
    //ws.setSupportMultipleWindows(true);
    // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ws.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
    //设置字体默认缩放大小
    ws.setTextZoom(100);
    // 不缩放
    this.setInitialScale(100);
    if(Build.VERSION.SDK_INT >= KITKAT) {
        //设置网页在加载的时候暂时不加载图片
        ws.setLoadsImagesAutomatically(true);
    } else {
        ws.setLoadsImagesAutomatically(false);
    }
    //默认关闭硬件加速
    setOpenLayerType(false);
    //默认不开启密码保存功能
    setSavePassword(false);
}