Java Code Examples for com.tencent.smtt.sdk.WebView#loadUrl()

The following examples show how to use com.tencent.smtt.sdk.WebView#loadUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: X5WebViewClient.java    From YCWebView with Apache License 2.0 6 votes vote down vote up
/**
 * android与js交互:
 * 首先我们拿到html中加载图片的标签img.
 * 然后取出其对应的src属性
 * 循环遍历设置图片的点击事件
 * 将src作为参数传给java代码
 * 这个循环将所图片放入数组,当js调用本地方法时传入。
 * 当然如果采用方式一获取图片的话,本地方法可以不需要传入这个数组
 * 通过js代码找到标签为img的代码块,设置点击的监听方法与本地的openImage方法进行连接
 * @param webView                       webview
 */
private void addImageArrayClickListener(WebView webView) {
    webView.loadUrl("javascript:(function(){" +
            "var objs = document.getElementsByTagName(\"img\"); " +
            "var array=new Array(); " +
            "for(var j=0;j<objs.length;j++){" +
            "    array[j]=objs[j].src; " +
            "}"+
            "for(var i=0;i<objs.length;i++)  " +
            "{"
            + "    objs[i].onclick=function()  " +
            "    {  "
            + "        window.imagelistener.openImage(this.src,array);  " +
            "    }  " +
            "}" +
            "})()");
}
 
Example 2
Source File: AgentWebX5Utils.java    From AgentWebX5 with Apache License 2.0 6 votes vote down vote up
public static final void clearWebView(WebView m) {

        if (m == null)
            return;
        if (Looper.myLooper() != Looper.getMainLooper())
            return;
        m.loadUrl("about:blank");
        m.stopLoading();
        if (m.getHandler() != null)
            m.getHandler().removeCallbacksAndMessages(null);
        m.removeAllViews();
        /*ViewGroup mViewGroup = null;
        if ((mViewGroup = ((ViewGroup) m.getParent())) != null)
            mViewGroup.removeView(m);*/
        m.setWebChromeClient(null);
        m.setWebViewClient(null);
        m.setTag(null);
        m.clearHistory();
        m.destroy();
        m = null;


    }
 
Example 3
Source File: WebViewCacheWrapper.java    From YCWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void loadUrl(WebView webView, String url, Map<String, String> additionalHttpHeaders) {
    if (!isValidUrl(url)) {
        return;
    }
    webView.loadUrl(url, additionalHttpHeaders);
    mReferer = webView.getUrl();
    mOrigin = getOriginUrl(mReferer);
    mUserAgent = webView.getSettings().getUserAgentString();
}
 
Example 4
Source File: BridgeUtil.java    From JsBridge with MIT License 5 votes vote down vote up
/**
 * js 文件将注入为第一个script引用
 *
 * @param view webview
 * @param url url
 */
public static void webViewLoadJs(WebView view, String url) {
    String js = "var newscript = document.createElement(\"script\");";
    js += "newscript.src=\"" + url + "\";";
    js += "document.scripts[0].parentNode.insertBefore(newscript,document.scripts[0]);";
    view.loadUrl("javascript:" + js);
}
 
Example 5
Source File: WebViewCacheWrapper.java    From YCWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void loadUrl(WebView webView, String url) {
    if (!isValidUrl(url)) {
        return;
    }
    webView.loadUrl(url);
    mReferer = webView.getUrl();
    mOrigin = getOriginUrl(mReferer);
    mUserAgent = webView.getSettings().getUserAgentString();
}
 
Example 6
Source File: X5WebViewClient.java    From YCWebView with Apache License 2.0 5 votes vote down vote up
/**
 * 通过js代码找到标签为img的代码块,设置点击的监听方法与本地的openImage方法进行连接
 * @param webView                       webview
 */
private void addImageClickListener(WebView webView) {
    webView.loadUrl("javascript:(function(){" +
            "var objs = document.getElementsByTagName(\"img\"); " +
            "for(var i=0;i<objs.length;i++)  " +
            "{"
            + "    objs[i].onclick=function()  " +
            "    {  "
            + "        window.imagelistener.openImage(this.src);  " +
            "    }  " +
            "}" +
            "})()");
}
 
Example 7
Source File: X5WebViewClient.java    From YCWebView with Apache License 2.0 5 votes vote down vote up
/**
 * 回退操作
 * @param webView                           webView
 * @return
 */
public final boolean pageGoBack(@NonNull WebView webView) {
    //判断是否可以回退操作
    if (pageCanGoBack()) {
        //获取最后停留的页面url
        final String url = popBackUrl();
        //如果不为空
        if (!TextUtils.isEmpty(url)) {
            webView.loadUrl(url);
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: BridgeUtil.java    From JsBridge with MIT License 5 votes vote down vote up
public static void webViewLoadLocalJs(WebView view, String path, String defaultJs, String customJs) {
    String jsContent = assetFile2Str(view.getContext(), path);
    if (!TextUtils.isEmpty(jsContent)) {
        jsContent = jsContent.replaceAll(defaultJs, customJs);
    }
    view.loadUrl("javascript:" + jsContent);
}
 
Example 9
Source File: CrazyDailyWebView.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void onPageStarted(WebView webView, String s, Bitmap bitmap) {
    if (!isLoaded) {
        isLoaded = true;
        webView.loadUrl(s);
    }
    super.onPageStarted(webView, s, bitmap);
}
 
Example 10
Source File: x5_MainActivity.java    From stynico with MIT License 5 votes vote down vote up
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
{
          if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP)
	{
              //当Sdk版本大于21时才能使用此方法
              view.loadUrl(request.getUrl().toString());
          }
          return super.shouldOverrideUrlLoading(view, String.valueOf(request));
      }
 
Example 11
Source File: BridgeUtil.java    From AndroidFrame with Apache License 2.0 5 votes vote down vote up
/**
 * js 文件将注入为第一个script引用
 * @param view WebView
 * @param url url
 */
public static void webViewLoadJs(WebView view, String url){
	String js = "var newscript = document.createElement(\"script\");";
	js += "newscript.src=\"" + url + "\";";
	js += "document.scripts[0].parentNode.insertBefore(newscript,document.scripts[0]);";
	view.loadUrl("javascript:" + js);
}
 
Example 12
Source File: BridgeUtil.java    From AndroidFrame with Apache License 2.0 5 votes vote down vote up
/**
 * js 文件将注入为第一个script引用
 * @param view WebView
 * @param url url
 */
public static void webViewLoadJs(WebView view, String url){
	String js = "var newscript = document.createElement(\"script\");";
	js += "newscript.src=\"" + url + "\";";
	js += "document.scripts[0].parentNode.insertBefore(newscript,document.scripts[0]);";
	view.loadUrl("javascript:" + js);
}
 
Example 13
Source File: X5WebView.java    From polyvideo with Apache License 2.0 4 votes vote down vote up
/**
 * 防止加载网页时调起系统浏览器
 */
public boolean shouldOverrideUrlLoading(WebView view, String url) {
	view.loadUrl(url);
	return true;
}
 
Example 14
Source File: X5WebView.java    From TBSVideoPlay with Apache License 2.0 4 votes vote down vote up
/**
 * 防止加载网页时调起系统浏览器
 */
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
}
 
Example 15
Source File: X5WebView.java    From CacheWebView with MIT License 4 votes vote down vote up
/**
 * 防止加载网页时调起系统浏览器
 */
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
}
 
Example 16
Source File: FileViewDemoMainActivity.java    From AndroidDocumentViewer with MIT License 4 votes vote down vote up
private void initWebView() {
    tbsWebView = (WebView) findViewById(R.id.tbs_webView);
    tbsWebView.loadUrl("file:///android_asset/test.html");
    tbsWebView.setDrawingCacheEnabled(true);
}
 
Example 17
Source File: BridgeUtil.java    From JsBridge with MIT License 4 votes vote down vote up
public static void webViewLoadLocalJs(WebView view, String path) {
    String jsContent = assetFile2Str(view.getContext(), path);
    view.loadUrl("javascript:" + jsContent);
}
 
Example 18
Source File: BridgeUtil.java    From AndroidFrame with Apache License 2.0 2 votes vote down vote up
/**
* 这里只是加载lib包中assets中的 WebViewJavascriptBridge.js
* @param view webview
* @param path 路径
*/
  public static void webViewLoadLocalJs(WebView view, String path){
      String jsContent = assetFile2Str(view.getContext(), path);
      view.loadUrl("javascript:" + jsContent);
  }
 
Example 19
Source File: BridgeUtil.java    From YCWebView with Apache License 2.0 2 votes vote down vote up
/**
* 这里只是加载lib包中assets中的 WebViewJavascriptBridge.js
* @param view webview
* @param path 路径
*/
  public static void webViewLoadLocalJs(WebView view, String path){
      String jsContent = assetFile2Str(view.getContext(), path);
      view.loadUrl("javascript:" + jsContent);
  }
 
Example 20
Source File: BridgeUtil.java    From AndroidFrame with Apache License 2.0 2 votes vote down vote up
/**
* 这里只是加载lib包中assets中的 WebViewJavascriptBridge.js
* @param view webview
* @param path 路径
*/
  public static void webViewLoadLocalJs(WebView view, String path){
      String jsContent = assetFile2Str(view.getContext(), path);
      view.loadUrl("javascript:" + jsContent);
  }