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


Java WebSettings.setCacheMode方法代码示例

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


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

示例1: onCreateView

import android.webkit.WebSettings; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_report, container, false);

    iv_menu = (ImageView) view.findViewById(R.id.iv_menu);
    iv_menu.setOnClickListener(this);
    textTitle = (TextView) view.findViewById(R.id.tvTitle);
    textTitle.setText(R.string.baobiao);
    btn_add = (Button) view.findViewById(R.id.btn_add);
    btn_add.setVisibility(View.INVISIBLE);

    webView = (WebView) view.findViewById(R.id.helpWebview);
    pbWebView = (ProgressBar) view.findViewById(R.id.pbWebView);
    ib_back = (ImageButton) view.findViewById(R.id.ib_back);
    ib_back.setOnClickListener(this);
    ib_back.setVisibility(View.INVISIBLE);
    ib_refresh = (ImageButton) view.findViewById(R.id.ib_refresh);
    ib_refresh.setOnClickListener(this);
    //启用支持javascript
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    getReportForm();

    return view;
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:30,代码来源:ReportFragment.java

示例2: setWebSettings

import android.webkit.WebSettings; //导入方法依赖的package包/类
private void setWebSettings() {
        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptEnabled(true);//开启对JavaScript的支持
        settings.setDefaultTextEncodingName("UTF-8");//设置字符编码
        settings.setSupportZoom(true);
        // 开启alert
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        // 开启按钮按下显示
        settings.setLightTouchEnabled(true);
//        settings.setUseWideViewPort(true);
        settings.setDomStorageEnabled(true);
        settings.setAppCacheEnabled(false);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        appendUserAgent("version", AppUtils.getNoPrefixVersionName(this));
        mWebView.requestFocus();
        mWebView.setWebChromeClient(chromeClient);
        mWebView.setWebViewClient(webViewClient);
    }
 
开发者ID:Jusenr,项目名称:AppFirCloud,代码行数:19,代码来源:WebViewActivity.java

示例3: initViews

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint({"SetJavaScriptEnabled"})
private void initViews() {
    this.mWebView.setVerticalScrollBarEnabled(false);
    this.mWebView.setHorizontalScrollBarEnabled(false);
    this.mWebView.setWebViewClient(new FbWebViewClient());
    this.mWebView.setWebChromeClient(this.mChromeClient);
    this.mWebView.clearFormData();
    WebSettings settings = this.mWebView.getSettings();
    settings.setSavePassword(false);
    settings.setSaveFormData(false);
    settings.setCacheMode(-1);
    settings.setNeedInitialFocus(false);
    settings.setBuiltInZoomControls(true);
    settings.setSupportZoom(true);
    settings.setRenderPriority(RenderPriority.HIGH);
    settings.setJavaScriptEnabled(true);
    if (!(this.mWeakContext == null || this.mWeakContext.get() == null)) {
        settings.setDatabaseEnabled(true);
        settings.setDatabasePath(((Context) this.mWeakContext.get()).getApplicationContext().getDir("databases", 0).getPath());
    }
    settings.setDomStorageEnabled(true);
    this.jsBridge.a(new JsListener(), "sdk_js_if");
    this.mWebView.clearView();
    this.mWebView.loadUrl(this.mUrl);
    this.mWebView.getSettings().setSavePassword(false);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:PKDialog.java

示例4: initViews

import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initViews() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_webview, this, true);
        mWebView = (MyWebView) findViewById(R.id.webview);
        mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
        mWebView.setWebViewClient(new MyClient());
//        mWebView.setWebChromeClient(new MyWebChromeClient());
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        webSettings.setBlockNetworkImage(true);
        mWebView.setOnScrollBottomListener(this);
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    }
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:17,代码来源:CustomWebView.java

示例5: b

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint({"SetJavaScriptEnabled"})
private void b() {
    this.i.setVerticalScrollBarEnabled(false);
    this.i.setHorizontalScrollBarEnabled(false);
    this.i.setWebViewClient(new FbWebViewClient());
    this.i.setWebChromeClient(this.mChromeClient);
    this.i.clearFormData();
    WebSettings settings = this.i.getSettings();
    settings.setSavePassword(false);
    settings.setSaveFormData(false);
    settings.setCacheMode(-1);
    settings.setNeedInitialFocus(false);
    settings.setBuiltInZoomControls(true);
    settings.setSupportZoom(true);
    settings.setRenderPriority(RenderPriority.HIGH);
    settings.setJavaScriptEnabled(true);
    if (!(this.c == null || this.c.get() == null)) {
        settings.setDatabaseEnabled(true);
        settings.setDatabasePath(((Context) this.c.get()).getApplicationContext().getDir
                ("databases", 0).getPath());
    }
    settings.setDomStorageEnabled(true);
    this.jsBridge.a(new JsListener(), "sdk_js_if");
    this.i.loadUrl(this.e);
    this.i.setLayoutParams(a);
    this.i.setVisibility(4);
    this.i.getSettings().setSavePassword(false);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:29,代码来源:TDialog.java

示例6: initView

import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
public void initView() {
    //不知道为什么如果webview用addview进FrameLyout会导致真机内存泄露,模拟器不管什么方式都内存泄露,不过真机不用addview就不会。
    WebSettings settings = wvDetailContent.getSettings();
    settings.setAppCacheEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setSupportZoom(true);
    wvDetailContent.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    nsvZhihuDetail.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (scrollY - oldScrollY > 0 && isBottomShow) {  //下移隐藏
                isBottomShow = false;
                flDetailBottom.animate().translationY(flDetailBottom.getHeight());
            } else if (scrollY - oldScrollY < 0 && !isBottomShow) {    //上移出现
                isBottomShow = true;
                flDetailBottom.animate().translationY(0);
            }
        }
    });
}
 
开发者ID:paterWang,项目名称:EasyReader,代码行数:33,代码来源:ZhiHuDetailActivity.java

示例7: 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

示例8: init

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void init(Context context) {
    this.setVerticalScrollBarEnabled(false);
    this.setHorizontalScrollBarEnabled(false);
    if (Build.VERSION.SDK_INT < 19) {
        removeJavascriptInterface("searchBoxJavaBridge_");
    }

    WebSettings localWebSettings = this.getSettings();
    try {
        // 禁用file协议,http://www.tuicool.com/articles/Q36ZfuF, 防止Android WebView File域攻击
        localWebSettings.setAllowFileAccess(false);
        localWebSettings.setSupportZoom(false);
        localWebSettings.setBuiltInZoomControls(false);
        localWebSettings.setUseWideViewPort(true);
        localWebSettings.setDomStorageEnabled(true);
        localWebSettings.setLoadWithOverviewMode(true);
        localWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        localWebSettings.setPluginState(PluginState.ON);
        // 启用数据库
        localWebSettings.setDatabaseEnabled(true);
        // 设置定位的数据库路径
        String dir = context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        localWebSettings.setGeolocationDatabasePath(dir);
        localWebSettings.setGeolocationEnabled(true);
        localWebSettings.setJavaScriptEnabled(true);
        localWebSettings.setSavePassword(false);
        String agent = localWebSettings.getUserAgentString();

        localWebSettings.setUserAgentString(agent);
        // setCookie(context, ".baidu.com", bdussCookie);

    } catch (Exception e1) {
        e1.printStackTrace();
    }
    this.setWebViewClient(new BridgeWebViewClient());
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:39,代码来源:BaseWebView.java

示例9: setWebViewSettings

import android.webkit.WebSettings; //导入方法依赖的package包/类
private void setWebViewSettings() {
        WebSettings webSettings = webView.getSettings();
        // 打开页面时, 自适应屏幕
        webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
        webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
        // 便页面支持缩放
        webSettings.setJavaScriptEnabled(true); //支持js
        webSettings.setSupportZoom(true); //支持缩放
//        webSettings.setBuiltInZoomControls(true); // 放大和缩小的按钮,容易引发异常 http://blog.csdn.net/dreamer0924/article/details/34082687

        webSettings.setAppCacheEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    }
 
开发者ID:wp521,项目名称:MyFire,代码行数:14,代码来源:NewsBrowserActivity.java

示例10: init

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
private void init() {
    WebSettings settings = getSettings();
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);

    setWebChromeClient(new WebChromeClient());
    setWebViewClient(new RTextEditorWebViewClient());
    addJavascriptInterface(this, "RTextEditorView");
    loadUrl(ASSETS_EDITOR_HTML);
}
 
开发者ID:jkennethcarino,项目名称:RTextEditorView,代码行数:13,代码来源:RTextEditorView.java

示例11: 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

示例12: onViewCreated

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint("JavascriptInterface")
@Override
public void onViewCreated(@Nullable Bundle savedInstanceState) {

    mWebView = getWebView();

    WebSettings settings = mWebView.getSettings();

    // To support for dom storage api
    settings.setDomStorageEnabled(true);

    // To support for javascript
    settings.setJavaScriptEnabled(true);

    // It is to increase the webView performance
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // It is also to increase the performance
    if (Build.VERSION.SDK_INT >= 19) {
        // chromium, enable hardware acceleration
        mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else {
        // older android version, disable hardware acceleration
        mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    mWebView.addJavascriptInterface(new WebSocketFactory(mWebView), "WebSocketFactory");

    setKeyListener();

    setForProgress();

    onViewReady(savedInstanceState);
}
 
开发者ID:sinhaDroid,项目名称:BlogBookApp,代码行数:34,代码来源:AbstractWebViewFragment.java

示例13: initialize

import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
  Log.i(TAG, "initialize");
  super.initialize(cordova, webView);
  WebView wv = (WebView) webView.getView();
  WebSettings ws = wv.getSettings();
  ws.setAppCacheEnabled(false);
  ws.setCacheMode(WebSettings.LOAD_NO_CACHE);
}
 
开发者ID:kroodle,项目名称:cordova-disable-http-cache,代码行数:10,代码来源:DisableHttpCachePlugin.java

示例14: a

import android.webkit.WebSettings; //导入方法依赖的package包/类
public static void a(WebSettings webSettings) {
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDefaultTextEncodingName(z[86]);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(2);
    webSettings.setSaveFormData(false);
    webSettings.setSavePassword(false);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:9,代码来源:a.java

示例15: 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


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