zoukankan      html  css  js  c++  java
  • android webview常用代码

    fun initWebviewSettgings(mWebView: WebView) {
    val webSetting: WebSettings = mWebView.getSettings()
    webSetting.javaScriptEnabled = true
    webSetting.defaultTextEncodingName = "UTF-8"
    webSetting.javaScriptCanOpenWindowsAutomatically = true
    webSetting.allowFileAccess = true
    //自适应屏幕
    webSetting.layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS
    // 设置可以支持缩放
    webSetting.setSupportZoom(true)
    // 设置出现缩放工具
    webSetting.builtInZoomControls = true
    //扩大比例的缩放
    webSetting.useWideViewPort = true
    webSetting.setSupportMultipleWindows(true)
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true)
    // webSetting.setDatabaseEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.domStorageEnabled = true // 打开本地缓存提供JS调用,至关重要

    webSetting.setGeolocationEnabled(true)
    // webSetting.setAppCacheMaxSize(Long.MAX_VALUE)
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.pluginState = WebSettings.PluginState.ON_DEMAND
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.cacheMode = WebSettings.LOAD_NO_CACHE
    mWebView.setBackgroundColor(85621)
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
    webSetting.mixedContentMode = android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
    }
    }
    //-------------------------------- WebViewClient
    // 拦截替换加载 资源  js,image  出错可以在  onReceivedHttpError 的request里看到
    // api>14有效
    override fun shouldInterceptRequest(p0: WebView, p1: String)

    // api>21有效
    override fun shouldInterceptRequest(p0: WebView, p1: WebResourceRequest)

    private fun handlerJsCache(
    url: String?
    ): WebResourceResponse? {
    try {
    if (url != null) {
    if (url.contains("api.map.baidu.com")) {
    if (BuildConfig.DEBUG) {
    LogUtils.w("----------------->>1 url = ${url}")
    }
    return WebResourceResponse()
    } else {
    if (url.endsWith(".js")) {
    val uri = Uri.parse(url)
    val fileName = uri.getLastPathSegment()
    for (assetsJs in jsAssetList) {
    if (fileName.equals(assetsJs)) {
    return WebResourceResponse(
    "application/javascript", "UTF-8", 200, "", paramMapJs, assets.open(assetsJs)
    )
    }
    }
    }
    }
    }
    } catch (e: Exception) {
    e.printStackTrace()
    }
    return null
    }
     
  • 相关阅读:
    《信息安全技术》实验四 木马及远程控制技术
    2017-2018-1 20155211 《信息安全系统设计基础》第9周学习总结
    linux 下c语言的pwd 实现
    2017-2018-1 20155211 实验三 实时系统
    信息安全技术 实验三 数字证书应用
    2017-2018-1 20155211 《信息安全系统设计基础》第八周学习总结
    2017-2018-1 20155211 《信息安全系统设计基础》第7周学习总结
    2017-2018-1  20155235 20155211 实验二 固件程序设计
    20155211实验2 Windows口令破解
    恢复旋转排序数组&&旋转字符串
  • 原文地址:https://www.cnblogs.com/caosq/p/14031123.html
Copyright © 2011-2022 走看看