当前位置: 首页>>代码示例>>Java>>正文


Java WebSettings.setAppCachePath方法代码示例

本文整理汇总了Java中android.webkit.WebSettings.setAppCachePath方法的典型用法代码示例。如果您正苦于以下问题:Java WebSettings.setAppCachePath方法的具体用法?Java WebSettings.setAppCachePath怎么用?Java WebSettings.setAppCachePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.webkit.WebSettings的用法示例。


在下文中一共展示了WebSettings.setAppCachePath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initWebViewSettings

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * @param webView
 */
@SuppressLint("SetJavaScriptEnabled")
public static void initWebViewSettings(WebView webView) {
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    webSettings.setDefaultFontSize(15);
    //设置缓存
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);

    webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webSettings.setAppCacheEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCachePath(AppConfig.WEB_CACHE_PATH);
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:21,代码来源:AppRouter.java

示例2: settingWebView

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * 初始化设置
 */
public void settingWebView() {
    WebSettings settings = getSettings();
    String ua = settings.getUserAgentString();
    // 设置浏览器UA,JS端通过UA判断是否属于Quick环境
    settings.setUserAgentString(ua + " QuickHybridJs/" + BuildConfig.VERSION_NAME);
    // 设置支持JS
    settings.setJavaScriptEnabled(true);
    // 设置是否支持meta标签来控制缩放
    settings.setUseWideViewPort(true);
    // 缩放至屏幕的大小
    settings.setLoadWithOverviewMode(true);
    // 设置内置的缩放控件(若SupportZoom为false,该设置项无效)
    settings.setBuiltInZoomControls(true);
    // 设置缓存模式
    // LOAD_DEFAULT 根据HTTP协议header中设置的cache-control属性来执行加载策略
    // LOAD_CACHE_ELSE_NETWORK 只要本地有无论是否过期都从本地获取
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setDomStorageEnabled(true);
    // 设置AppCache 需要H5页面配置manifest文件(官方已不推介使用)
    String appCachePath = getContext().getCacheDir().getAbsolutePath();
    settings.setAppCachePath(appCachePath);
    settings.setAppCacheEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // 强制开启android webview debug模式使用Chrome inspect(https://developers.google.com/web/tools/chrome-devtools/remote-debugging/)
        WebView.setWebContentsDebuggingEnabled(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
    }
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:34,代码来源:QuickWebView.java

示例3: initView

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint("SetJavaScriptEnabled") private void initView(@Nullable AttributeSet attrs) {
    if (isInEditMode()) return;
    if (attrs != null) {
        TypedArray tp = getContext().obtainStyledAttributes(attrs, R.styleable.PrettifyWebView);
        try {
            int color = tp.getColor(R.styleable.PrettifyWebView_webview_background, ViewHelper.getWindowBackground(getContext()));
            setBackgroundColor(color);
        } finally {
            tp.recycle();
        }
    }
    setWebChromeClient(new ChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        setWebViewClient(new WebClient());
    } else {
        setWebViewClient(new WebClientCompat());
    }
    WebSettings settings = getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAppCachePath(getContext().getCacheDir().getPath());
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setDefaultTextEncodingName("utf-8");
    settings.setLoadsImagesAutomatically(true);
    settings.setBlockNetworkImage(false);
    setOnLongClickListener((view) -> {
        WebView.HitTestResult result = getHitTestResult();
        if (hitLinkResult(result) && !InputHelper.isEmpty(result.getExtra())) {
            AppHelper.copyToClipboard(getContext(), result.getExtra());
            return true;
        }
        return false;
    });
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:35,代码来源:PrettifyWebView.java

示例4: init

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint("SetJavaScriptEnabled")
private void init(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray tp = getContext().obtainStyledAttributes(attrs, R.styleable.CodeWebView);
        try {
            backgroundColor = tp.getColor(R.styleable.CodeWebView_webview_background,
                    ViewUtils.getWindowBackground(getContext()));
            setBackgroundColor(backgroundColor);
        } finally {
            tp.recycle();
        }
    }

    setWebChromeClient(new ChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        setWebViewClient(new WebClientN());
    } else {
        setWebViewClient(new WebClient());
    }
    WebSettings settings = getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAppCachePath(getContext().getCacheDir().getPath());
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setDefaultTextEncodingName("utf-8");
    settings.setLoadsImagesAutomatically(true);
    settings.setBlockNetworkImage(false);
    setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            WebView.HitTestResult result = getHitTestResult();
            if (hitLinkResult(result) && !StringUtils.isBlank(result.getExtra())) {
                AppUtils.copyToClipboard(getContext(), result.getExtra());
                return true;
            }
            return false;
        }
    });
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:40,代码来源:CodeWebView.java

示例5: initWebSettings

import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initWebSettings() {
  WebSettings settings = mWebView.getSettings();
  //支持获取手势焦点
  mWebView.requestFocusFromTouch();
  //支持JS
  settings.setJavaScriptEnabled(true);
  //支持插件
  settings.setPluginState(WebSettings.PluginState.ON);
  //设置适应屏幕
  settings.setUseWideViewPort(true);
  settings.setLoadWithOverviewMode(true);
  //支持缩放
  settings.setSupportZoom(false);
  //隐藏原生的缩放控件
  settings.setDisplayZoomControls(false);
  //支持内容重新布局
  settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
  settings.supportMultipleWindows();
  settings.setSupportMultipleWindows(true);
  //设置缓存模式
  settings.setDomStorageEnabled(true);
  settings.setDatabaseEnabled(true);
  settings.setCacheMode(WebSettings.LOAD_DEFAULT);
  settings.setAppCacheEnabled(true);
  settings.setAppCachePath(mWebView.getContext().getCacheDir().getAbsolutePath());

  //设置可访问文件
  settings.setAllowFileAccess(true);
  //当webview调用requestFocus时为webview设置节点
  settings.setNeedInitialFocus(true);
  //支持自动加载图片
  if (Build.VERSION.SDK_INT >= 19) {
    settings.setLoadsImagesAutomatically(true);
  } else {
    settings.setLoadsImagesAutomatically(false);
  }
  settings.setNeedInitialFocus(true);
  //设置编码格式
  settings.setDefaultTextEncodingName("UTF-8");
}
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:41,代码来源:WebViewUI.java

示例6: enableCache

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * Function to enable caching
 */
private void enableCache() {
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setAppCacheMaxSize(5 * 1024 * 1024); // 5MB
    webSettings.setAppCachePath(getContext().getCacheDir().getAbsolutePath());
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default

    if (!AppUtils.isNetworkConnected(getContext())) { // loading offline
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    }
}
 
开发者ID:mangoblogger,项目名称:MangoBloggerAndroidApp,代码行数:16,代码来源:WebFragment.java

示例7: initWebView

import android.webkit.WebSettings; //导入方法依赖的package包/类
public void initWebView(WebView webView) {
        webView.setVerticalScrollBarEnabled(false);
        webView.setBackgroundColor(getResources().getColor(R.color.white));
        //设置webview的配置
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

        WebSettings webseting = webView.getSettings();
        // 支持JavaScript
        webseting.setJavaScriptEnabled(true);
        // 支持保存数据
        webseting.setSaveFormData(false);
        webseting.setDomStorageEnabled(true);
//		webseting.setAppCacheMaxSize(1024 * 1024 * 8);// 设置缓冲大小,我设的是8M
        String appCacheDir = getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
        webseting.setAppCachePath(appCacheDir);
        webseting.setUserAgentString(Config.FORMAT_USER_AGENT);
        webseting.setLoadWithOverviewMode(true);
        webseting.setUseWideViewPort(true);
        webseting.setDatabaseEnabled(true);
        webseting.setAllowFileAccess(true);
        webseting.setCacheMode(WebSettings.LOAD_DEFAULT);
        /*强制webview使用标准字号大小*/
        webseting.setTextZoom(100);

        // webseting.setBlockNetworkImage(true);
        webseting.setLoadsImagesAutomatically(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            webView.setWebContentsDebuggingEnabled(true);// Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application.
        }

        //移除webkit内部存在安全漏洞的javascript接口
        webView.removeJavascriptInterface("searchBoxJavaBridge_");
        webView.removeJavascriptInterface("accessibility");
        webView.removeJavascriptInterface("accessibilityTraversal");

    }
 
开发者ID:AlpacaNotSheep,项目名称:hybrid,代码行数:38,代码来源:BaseWebActivity.java

示例8: initializeSettings

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
public void initializeSettings(WebSettings settings, Context context) {
	//setPageCacheCapacity2(settings);
	if (API < 18) {
		settings.setAppCacheMaxSize(Long.MAX_VALUE);
	}
	if (API < 17) {
		settings.setEnableSmoothTransition(true);
	}
	if (API > 16) {
		settings.setMediaPlaybackRequiresUserGesture(true);
	}
	if (API >= Build.VERSION_CODES.LOLLIPOP && !mBrowserController.isIncognito()) {
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
	} else if (API >= Build.VERSION_CODES.LOLLIPOP) {
		// We're in Incognito mode, reject
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
	}
	settings.setDomStorageEnabled(true);
	settings.setAppCacheEnabled(true);
	settings.setCacheMode(WebSettings.LOAD_DEFAULT);
	settings.setDatabaseEnabled(true);
	settings.setSupportZoom(true);
	settings.setBuiltInZoomControls(true);
	settings.setDisplayZoomControls(false);
	settings.setAllowContentAccess(true);
	settings.setAllowFileAccess(true);
	settings.setDefaultTextEncodingName("utf-8");
	if (API > 16) {
		settings.setAllowFileAccessFromFileURLs(false);
		settings.setAllowUniversalAccessFromFileURLs(false);
	}

	settings.setAppCachePath(context.getDir("appcache", 0).getPath());
	settings.setGeolocationDatabasePath(context.getDir("geolocation", 0).getPath());
	if (API < Build.VERSION_CODES.KITKAT) {
		settings.setDatabasePath(context.getDir("databases", 0).getPath());
	}


}
 
开发者ID:NewCasino,项目名称:browser,代码行数:43,代码来源:LightningView.java

示例9: initViews

import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initViews() {
    Method method;
    WebSettings settings = this.mWebView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setUserAgentString(settings.getUserAgentString() + "/" + UA_PREFIX + this.jsBridge.getVersion() + "/sdk");
    settings.setJavaScriptEnabled(true);
    Class cls = settings.getClass();
    try {
        method = cls.getMethod("setPluginsEnabled", new Class[]{Boolean.TYPE});
        if (method != null) {
            method.invoke(settings, new Object[]{Boolean.valueOf(true)});
        }
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (Throwable th) {
        th.printStackTrace();
    }
    try {
        method = cls.getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
        if (method != null) {
            method.invoke(settings, new Object[]{Boolean.valueOf(true)});
        }
    } catch (SecurityException e2) {
        e2.printStackTrace();
    } catch (NoSuchMethodException e3) {
    } catch (IllegalArgumentException e4) {
    } catch (IllegalAccessException e5) {
    } catch (InvocationTargetException e6) {
    }
    settings.setAppCachePath(getWebViewCacheDir());
    settings.setDatabasePath(getWebViewCacheDir());
    settings.setDatabaseEnabled(true);
    settings.setAppCacheEnabled(true);
    if (supportWebViewFullScreen()) {
        settings.setUseWideViewPort(true);
        if (VERSION.SDK_INT >= 7) {
            try {
                cls.getMethod("setLoadWithOverviewMode", new Class[]{Boolean.TYPE}).invoke(settings, new Object[]{Boolean.valueOf(true)});
            } catch (Exception e7) {
            }
        }
        if (SystemUtils.isSupportMultiTouch()) {
            if (SystemUtils.getAndroidSDKVersion() < 11) {
                try {
                    Field declaredField = WebView.class.getDeclaredField("mZoomButtonsController");
                    declaredField.setAccessible(true);
                    ZoomButtonsController zoomButtonsController = new ZoomButtonsController(this.mWebView);
                    zoomButtonsController.getZoomControls().setVisibility(8);
                    declaredField.set(this.mWebView, zoomButtonsController);
                } catch (Exception e8) {
                }
            } else {
                try {
                    this.mWebView.getSettings().getClass().getMethod("setDisplayZoomControls", new Class[]{Boolean.TYPE}).invoke(this.mWebView.getSettings(), new Object[]{Boolean.valueOf(false)});
                } catch (Exception e9) {
                }
            }
        }
    }
    this.mWebView.setWebViewClient(new d());
    this.mWebView.setWebChromeClient(new c());
    this.mWebView.setDownloadListener(this.mDownloadListener);
    this.mWebView.loadUrl(this.url);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:65,代码来源:AppbarActivity.java

示例10: initSettings

import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initSettings() {
    WebSettings webSettings = mDXHWebView.getSettings();

    webSettings.setJavaScriptEnabled(true);
    if (Build.VERSION.SDK_INT >= 16) {
        webSettings.setAllowFileAccessFromFileURLs(true);
    }
    webSettings.setDomStorageEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);

    if (NetworkUtils.isConnected(mContext) ){
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    } else {
        webSettings.setCacheMode(
                WebSettings.LOAD_CACHE_ELSE_NETWORK);



    }
    webSettings.setDatabaseEnabled(true);
    webSettings.setAppCacheMaxSize(1024 * 1024 * 8);
    webSettings.setAppCacheEnabled(true);



    //File fDatabase = new File(mContext.getCacheDir().getAbsolutePath(),"webview_db");
    //webSettings.setDatabasePath(fDatabase.getAbsolutePath());
    File fAppCache = new File(mContext.getCacheDir().getAbsolutePath(),"webview_cache");
    webSettings.setAppCachePath(fAppCache.getAbsolutePath());

    webSettings.setBuiltInZoomControls(true);// api-3
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
    if (Build.VERSION.SDK_INT >= 11) {
        webSettings.setDisplayZoomControls(false);// api-11
    }

    //http://wiki.jikexueyuan.com/project/chrome-devtools/remote-debugging-on-android.html
    if (Build.VERSION.SDK_INT >= 19) {//for chrome debug
        WebView.setWebContentsDebuggingEnabled(true);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        webSettings.setMixedContentMode(
                WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    }
}
 
开发者ID:yale8848,项目名称:CacheWebView,代码行数:50,代码来源:TestWebView.java


注:本文中的android.webkit.WebSettings.setAppCachePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。