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

The following examples show how to use com.tencent.smtt.sdk.WebSettings#setAppCacheMaxSize() . 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: X5WebView.java    From TBSVideoPlay with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化webview设置
 */
private void initWebViewSettings() {
    WebSettings webSetting = this.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    webSetting.setAllowFileAccess(true);
    webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webSetting.setSupportZoom(true);
    webSetting.setBuiltInZoomControls(true);
    webSetting.setUseWideViewPort(true);
    webSetting.setSupportMultipleWindows(true);
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.setDomStorageEnabled(true);
    webSetting.setGeolocationEnabled(true);
    webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
}
 
Example 2
Source File: X5WebView.java    From polyvideo with Apache License 2.0 6 votes vote down vote up
private void initWebViewSettings() {
	WebSettings webSetting = this.getSettings();
	webSetting.setJavaScriptEnabled(true);
	webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
	webSetting.setAllowFileAccess(true);
	webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
	webSetting.setSupportZoom(true);
	webSetting.setBuiltInZoomControls(true);
	webSetting.setUseWideViewPort(true);
	webSetting.setSupportMultipleWindows(true);
	// webSetting.setLoadWithOverviewMode(true);
	webSetting.setAppCacheEnabled(true);
	// webSetting.setDatabaseEnabled(true);
	webSetting.setDomStorageEnabled(true);
	webSetting.setGeolocationEnabled(true);
	webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
	// webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
	webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
	// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
	webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

	// this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
	// settings 的设计
}
 
Example 3
Source File: X5WebView.java    From Readhub with Apache License 2.0 6 votes vote down vote up
private void initWebViewSettings() {
	WebSettings webSetting = this.getSettings();
	webSetting.setJavaScriptEnabled(true);
	webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
	webSetting.setAllowFileAccess(true);
	webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
	webSetting.setSupportZoom(false);
	webSetting.setBuiltInZoomControls(false);
	webSetting.setUseWideViewPort(true);
	webSetting.setSupportMultipleWindows(true);
	webSetting.setAppCacheEnabled(true);
	webSetting.setDomStorageEnabled(true);
	webSetting.setGeolocationEnabled(true);
	webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
	webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
	webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

}
 
Example 4
Source File: X5WebView.java    From FastAndroid with Apache License 2.0 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initWebViewSettings() {
    WebSettings webSetting = this.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    webSetting.setAllowFileAccess(true);
    webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webSetting.setSupportZoom(true);
    webSetting.setBuiltInZoomControls(true);
    webSetting.setUseWideViewPort(true);
    webSetting.setSupportMultipleWindows(true);
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.setDomStorageEnabled(true);
    webSetting.setGeolocationEnabled(true);
    webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
    // settings 的设计
}
 
Example 5
Source File: X5WebView.java    From CacheWebView with MIT License 6 votes vote down vote up
private void initWebViewSettings() {
    WebSettings webSetting = this.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    webSetting.setAllowFileAccess(true);
    webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webSetting.setSupportZoom(true);
    webSetting.setBuiltInZoomControls(true);
    webSetting.setUseWideViewPort(true);
    webSetting.setSupportMultipleWindows(true);
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.setDomStorageEnabled(true);
    webSetting.setGeolocationEnabled(true);
    webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
    // settings 的设计
}
 
Example 6
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 7
Source File: WebviewActivity.java    From AndroidFrame with Apache License 2.0 4 votes vote down vote up
private void initWebview() {
    mWebView = findViewById(R.id.webview);
    mBridge = new WebViewJavascriptBridge(this, sHandler, mWebView);
    mWebView.addJavascriptInterface(mBridge, "AndroidWebViewJavascriptBridge");
    WebSettings webSetting = mWebView.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    webSetting.setAllowFileAccess(true);
    webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSetting.setSupportZoom(true);
    webSetting.setBuiltInZoomControls(true);
    webSetting.setUseWideViewPort(true);
    webSetting.setSupportMultipleWindows(true);
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.setDomStorageEnabled(true);
    webSetting.setGeolocationEnabled(true);
    webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
    String userAgent = webSetting.getUserAgentString() + " " + AGENG_STR
            + AGENG_STR_SUFFIX + "/" + getVersionName() + "/QD"
            + getQudaoName() + "/";
    webSetting.setUserAgentString(userAgent);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView webView, String s) {
            InputStream fs = WebviewActivity.this.getResources().openRawResource(
                    R.raw.jsbridge_init);
            String jsbridgeInitScript = getLocalText(fs);
            String js1 = "javascript:var evtAndroidJSB = document.createEvent('Event');"
                    + "evtAndroidJSB.initEvent('AndroidWebViewJavascriptBridgeReady', false, false); "
                    + "document.dispatchEvent(evtAndroidJSB);";
            String js2 = "javascript: " + jsbridgeInitScript;
            if (android.os.Build.VERSION.SDK_INT <= 18) {
                mWebView.loadUrl(js1);
                mWebView.loadUrl(js2);
            } else {
                mWebView.evaluateJavascript(js1, null);
                mWebView.evaluateJavascript(js2, null);
            }
            super.onPageFinished(webView, s);
        }
    });
}
 
Example 8
Source File: CrazyDailyWebView.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("all")
private void init(Context context) {
    WebSettings setttings = getSettings();
    setttings.setJavaScriptEnabled(true);//打开js
    setttings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//设置布局
    setttings.setDomStorageEnabled(true);//打开Dom Storage
    setttings.setDatabaseEnabled(true);//打开Database
    setttings.setAppCacheEnabled(true);//打开App Cache
    setttings.setAppCacheMaxSize(Long.MAX_VALUE);
    File cacheDir = new File(context.getExternalCacheDir(), CacheConstant.CACHE_DIR_WEB);
    if (!cacheDir.exists()) {
        cacheDir.mkdirs();
    }
    setttings.setAppCachePath(cacheDir.getAbsolutePath());//设置App Cache缓存目录
    setttings.setSupportMultipleWindows(false);//不支持多窗口
    setttings.setJavaScriptCanOpenWindowsAutomatically(true);//支持js打开新窗口
    setttings.setAllowFileAccess(true);//启用WebView访问文件数据
    setttings.setSupportZoom(true);//支持缩放
    setttings.setDisplayZoomControls(false);//隐藏webview缩放按钮
    setttings.setBuiltInZoomControls(true);//支持手势缩放
    setttings.setLoadWithOverviewMode(true);//缩放至屏幕大小
    setttings.setUseWideViewPort(true);//调整屏幕自适应
    setttings.setDefaultTextEncodingName("utf-8");//设置编码格式为utf-8
    setttings.setLoadsImagesAutomatically(true);//支持自动加载图片
    setttings.setSavePassword(false);//禁止密码保存在本地
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // https中支持访问http
        setttings.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // 支持第三方的cookie同步
        CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
    }
    String ua = setttings.getUserAgentString();
    setttings.setUserAgentString(String.format("%s CrazyDaily %s", ua, DeviceUtil.getVersionName()));//重置ua
    setWebViewClient(new CrazyDailyWebViewClient());
    setWebChromeClient(new CrazyDailyWebChromeClient());
    setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
            if (mDownloadCallback != null) {
                mDownloadCallback.onDownload(url, contentLength);
            }
        }
    });
}
 
Example 9
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 10
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);
}