本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
示例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;
}
示例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);
}
示例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);
}
示例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");
}
示例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);
}
示例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);
}
}
}
示例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;
}
});
}
示例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);
}