首页 > 学院 > 开发设计 > 正文

WebView加载h5视频网页

2019-11-07 23:10:57
字体:
来源:转载
供稿:网友
    webView1 = (WebView) findViewById(R.id.webView1);        javascriptInterface = new JavascriptInterface(this);        webSettings = webView1.getSettings();        webSettings.setJavaScriptEnabled(true);        webSettings.setDomStorageEnabled(true);        webSettings.setUseWideViewPort(true);        webSettings.setLoadWithOverviewMode(true);        webSettings.setUserAgentString(webSettings.getUserAgentString());        webSettings.setDatabaseEnabled(true);        String dir = context.getDir("database", Context.MODE_PRIVATE).getPath();        webSettings.setDatabasePath(dir);        webSettings.setGeolocationDatabasePath(dir);        webSettings.setAppCacheEnabled(true);        String cacheDir = context.getDir("cache", Context.MODE_PRIVATE).getPath();        webSettings.setAppCachePath(cacheDir);        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);        webSettings.setAppCacheMaxSize(1024 * 1024 * 10);        webSettings.setAllowFileaccess(true);        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);        webSettings.setBuiltInZoomControls(true);        webSettings.setDisplayZoomControls(true);        webSettings.setSupportZoom(true);        webSettings.setPluginState(WebSettings.PluginState.ON);        webView1.setWebViewClient(new MyWebViewClient());        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);        }        webView1.setWebChromeClient(new MyWebChromeClient());//        webView1.loadUrl("http://v.youku.com/v_show/id_XMTg0MzU5Nzc3Ng==.html");    }    // js通信接口    public static class JavaScriptInterface {        private Context context;        public JavaScriptInterface(Context context) {            this.context = context;        }    }    private class MyWebViewClient extends WebViewClient {        @Override        public void onPageFinished(WebView view, String url) {            super.onPageFinished(view, url);            // html加载完成之后,添加监听图片的点击js函数        }        @Override        public boolean shouldOverrideUrlLoading(WebView view, String url) {            view.loadUrl(url);            return true;        }        @Override        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {            handler.proceed();        }    }    /**     * 设置进度条和提示框     */    private class MyWebChromeClient extends WebChromeClient {        //该方法中可以设置进度条        @Override        public void onProgressChanged(WebView view, int newProgress) {            super.onProgressChanged(view, newProgress);        }        //发方法中可以处理提示框        @Override        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {            return super.onJsAlert(view, url, message, result);        }    }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表