當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。