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


Java WebResourceRequest类代码示例

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


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

示例1: shouldInterceptRequest

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {

	/*
	ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
	if (mAdBlock.isAd(request.getUrl().getHost())) {

		return new WebResourceResponse("text/plain", "utf-8", EMPTY);
	}

	if(request.getUrl().getHost().indexOf("127.0.0.1")>=0){
		//ToastUtil.showMessage("this site is insecure");

		return new WebResourceResponse("text/plain", "utf-8", EMPTY);
	}
	*/

	return super.shouldInterceptRequest(view, request);
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:20,代码来源:LightningView.java

示例2: setupWebView

import android.webkit.WebResourceRequest; //导入依赖的package包/类
private void setupWebView() {
    WebSettings settings = mWvWebview.getSettings();

    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(false);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setDomStorageEnabled(true);

    WebViewClient webViewClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(String.valueOf(request.getUrl()));
            return true;
        }
    };

    mWvWebview.setWebViewClient(webViewClient);
}
 
开发者ID:coderwjq,项目名称:ZhaZhaShop,代码行数:20,代码来源:WebViewActivity.java

示例3: shouldOverrideUrlLoading

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@TargetApi(24)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
	Log.d(TAG, "shouldOverrideUrlLoading() called with: request = [" + request.getUrl() + "]");
	if (pager.webviewClient != null) {
		if (pager.webviewClient.shouldOverrideUrlLoading(view, request)) {
			return true;
		}
	}

	if (handleUrlLoading(view, request.getUrl().toString())) {
		return true;
	}

	return super.shouldOverrideUrlLoading(view, request);
}
 
开发者ID:fengshihao,项目名称:WebPager,代码行数:17,代码来源:PagerWebViewClient.java

示例4: shouldInterceptRequest

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
	Uri url = request.getUrl();
	if ("https://www.fengshihao.com/user.js".indexOf(url.toString()) == 0) {
		final WebResourceResponse userjs = new WebResourceResponse("text/javascript", "UTF-8",
			new ByteArrayInputStream("console.log('hello user js');".getBytes()));
		return userjs;
	}
	return super.shouldInterceptRequest(view, request);
}
 
开发者ID:fengshihao,项目名称:WebPager,代码行数:12,代码来源:PagerWebViewClient.java

示例5: shouldInterceptRequest

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {

    WebResourceResponse webResourceResponse = null;
    if (mCustomWebViewClient!=null){
        webResourceResponse =  mCustomWebViewClient.shouldInterceptRequest(view,request);
    }
    if (webResourceResponse != null){
        return webResourceResponse;
    }
    if (!mIsEnableCache){
        return null;
    }
    return mWebViewCache.getWebResourceResponse(this,request.getUrl().toString(),
            mCacheStrategy,mEncoding,mCacheInterceptor);
}
 
开发者ID:yale8848,项目名称:CacheWebView,代码行数:18,代码来源:CacheWebViewClient.java

示例6: shouldInterceptRequest

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
        //此处对文件资源,js,css等请求资源进行拦截,替换
        Log.d(TAG, "shouldInterceptRequest: request = \n" +
                "\nurl = " + request.getUrl().toString() +
                "\nmethod = " + request.getMethod() +
                "\nheaders = " + request.getRequestHeaders().toString());
//        String url = request.getUrl().toString();
//        if ((url.startsWith("https://") || url.startsWith("http://")) && (url.endsWith(".png") || url.endsWith(".jpg"))) {
//            Log.d(TAG, "拦截资源 :" + url);
//            try {
//                WebResourceResponse response = new WebResourceResponse(MimeTypeMap.getFileExtensionFromUrl(".jpg"), "utf-8", FileUtils.getInputStreamFromAssets("img/dog.jpg"));
//                return response;
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
        return super.shouldInterceptRequest(view, request);
    }
 
开发者ID:jiangkang,项目名称:KTools,代码行数:21,代码来源:KWebViewClient.java

示例7: onCreate

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    wv_test = (WebView)findViewById(R.id.wv_test) ;
    wv_test.getSettings().setJavaScriptEnabled(true);
    /* "JSInterface" ==> window.JSInterface
     * class JSInterface all @javascriptInterface methods
     * js can call JSInterface.method()*/
    wv_test.addJavascriptInterface(new JSInterface(MainActivity.this),"JSInterface");
    /* at webivew not brower*/
    wv_test.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return true ;
        }
    });
    wv_test.loadUrl("file:///android_asset/JSInterface.html");
    //wv_test.loadUrl("http://127.0.0.1:8080/JSInterface.html");
}
 
开发者ID:HuChengSheng,项目名称:JSInterface,代码行数:21,代码来源:MainActivity.java

示例8: shouldOverrideUrlLoading

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        String url = request.getUrl().toString();
        if (view instanceof AbstractWebKit) {
            boolean flag = false;
            if (interceptor != null) {
                flag = interceptor.shouldOverrideUrlLoading((AbstractWebKit) view, url);
            }
            if (flag) {
                return true;
            }
        }
        String lowurl = url.toLowerCase();
        if (lowurl.startsWith("http:") || lowurl.startsWith("https:")) {
            view.loadUrl(url, headers != null ? headers.generateHeaders() : null);
            return true;
        }
    }
    return true;
}
 
开发者ID:LiangMaYong,项目名称:android-base,代码行数:22,代码来源:AbstractWebkitClient.java

示例9: onPrepareWebView

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onPrepareWebView(WebView webView) {
    super.onPrepareWebView(webView);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return false; // let the web view handle the url
        }
    });
    webView.getSettings().setJavaScriptEnabled(true);
    // https://labs.mwrinfosecurity.com/blog/webview-addjavascriptinterface-remote-code-execution/
    // FIXME: 2016/9/20 fix it later
    webView.addJavascriptInterface(new JsInterface(this), getString(R.string.web_image_click_target));
    // http://blog.csdn.net/u013107656/article/details/51729398
    webView.removeJavascriptInterface("searchBoxJavaBridge_");
    webView.removeJavascriptInterface("accessibilityTraversal");
    webView.removeJavascriptInterface("accessibility");
    webView.setOnTouchListener(this);
}
 
开发者ID:TomeOkin,项目名称:LsPush,代码行数:21,代码来源:CollectionTargetActivity.java

示例10: onCreate

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setupActionBar();

    Intent webViewIntent = getIntent();
    String url = webViewIntent.getStringExtra(EXTRA_URL);

    webView = findViewById(R.id.webview);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return false;
        }
    });
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.loadUrl(url);
}
 
开发者ID:infobip,项目名称:mobile-messaging-sdk-android,代码行数:24,代码来源:WebViewActivity.java

示例11: onCreate

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = (WebView) findViewById(R.id.web_view);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

            return super.shouldOverrideUrlLoading(view, request);

        }
    });
    webView.loadUrl("http://www.baidu.com");
}
 
开发者ID:huang303513,项目名称:AndroidBasicCommonDemos,代码行数:17,代码来源:MainActivity.java

示例12: shouldInterceptRequest

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (mAdBlock.isAd(request.getUrl().toString())) {
            String stweb = "\n \n \n \n BLOCKED BY AD-BLOCKER" + "\n" +
                    "\n" +
                    " \n" +
                    " \n" +
                    " \n - TO DISABLE AD-BLOCKER GO TO SETTINGS/GENEARL SETTING";
            ByteArrayInputStream EMPTY = new ByteArrayInputStream(stweb.getBytes());

            return new WebResourceResponse("text/plain", "utf-8", EMPTY);
        }
    }
    return super.shouldInterceptRequest(view, request);
}
 
开发者ID:javadtaghia,项目名称:DeeBrowser,代码行数:17,代码来源:LightningView.java

示例13: onReceivedError

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
  super.onReceivedError(view, request, error);
  Crashlytics.log(5, "KolibriWebView",
      "onReceivedError() called with: request = [" + request + "], error = [" + error + "]");

  // We ignore errors regarding assets loading,
  // so in this case we check if the request url and webview url are same
  if (request.getUrl().toString().equals(view.getUrl()) || request.isForMainFrame()) {
    for (KolibriWebViewClient webClient : webClients) {
      webClient.onReceivedError(view, request, error);
    }
  }
}
 
开发者ID:azmedien,项目名称:kolibri-android,代码行数:16,代码来源:KolibriWebView.java

示例14: initListener

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@Override
protected void initListener() {

    mFab.setOnClickListener(v -> SnackbarUtil.show(this, "喜欢就点个star吧!"));

    mWeb.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(request.getUrl().toString());
            return true;
        }
    });
}
 
开发者ID:crazysunj,项目名称:CrazyDaily,代码行数:14,代码来源:ZhihuNewsDetailActivity.java

示例15: onReceivedError

import android.webkit.WebResourceRequest; //导入依赖的package包/类
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {

  super.onReceivedError(view, request, error);
  String errorHtml = "<html><body><h2>找不到网页</h2></body></html>";
  view.loadDataWithBaseURL(null, errorHtml, "text/html", "UTF-8", null);
}
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:8,代码来源:BrowserActivity.java


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