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


Java WebResourceResponse类代码示例

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


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

示例1: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的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: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    // Intercept requests for private images and add the WP.com authorization header
    if (mIsPrivatePost && !TextUtils.isEmpty(mToken) && UrlUtils.isImageUrl(url)) {
        try {
            URL imageUrl = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
            conn.setReadTimeout(WPRestClient.REST_TIMEOUT_MS);
            conn.setConnectTimeout(WPRestClient.REST_TIMEOUT_MS);
            conn.setRequestProperty("Authorization", "Bearer " + mToken);
            conn.setRequestProperty("User-Agent", WordPress.getUserAgent());
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.connect();
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream inputStream = new BufferedInputStream(conn.getInputStream());
                return new WebResourceResponse(conn.getContentType(), "UTF-8", inputStream);
            }
        } catch (IOException e) {
            AppLog.e(AppLog.T.READER, e);
        }
    }

    return null;
}
 
开发者ID:ldsddn,项目名称:wordpress_app_android,代码行数:25,代码来源:ReaderWebView.java

示例3: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的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

示例4: getResource

import android.webkit.WebResourceResponse; //导入依赖的package包/类
public WebResourceResponse getResource(String path) {
    int index = path.lastIndexOf(".");
    if (index == -1) {
        return null;
    }
    String ext = path.substring(index);
    Log.d("wlx", ext);
    String mini = (String) this.minitype.get(ext);
    if (mini == null) {
        return null;
    }
    try {
        return new WebResourceResponse(mini, "UTF-8", new FileInputStream(this.resource + path));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:NativeWebViewUtils.java

示例5: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    WebResourceResponse webResourceResponse = null;
    if (mCustomWebViewClient!=null){
        webResourceResponse =  mCustomWebViewClient.shouldInterceptRequest(view,url);
    }
    if (webResourceResponse != null){
        return webResourceResponse;

    }
    if (!mIsEnableCache){
        return null;
    }
    return mWebViewCache.getWebResourceResponse(this,url,mCacheStrategy,
            mEncoding,mCacheInterceptor);

}
 
开发者ID:yale8848,项目名称:CacheWebView,代码行数:18,代码来源:CacheWebViewClient.java

示例6: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的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: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    // Uses cache to determine if the url is ad,
    // and returns an empty resource for ads.
    boolean ad;
    if (!mLoadedUrls.containsKey(url)) {
        ad = mAdBlocker.isAd(url);
        mLoadedUrls.put(url, ad);
    } else {
        ad = mLoadedUrls.get(url);
    }
    // Verbose blocked or passed urls
    Log.v(getClass().getSimpleName(), (ad ? "Blocked" : "Pass") + ": " + Uri.parse(url).getHost());
    // Return appropriate response
    if(ad) {
        return mAdBlocker.createEmptyResource();
    }
    return super.shouldInterceptRequest(view, url);
}
 
开发者ID:dipu-bd,项目名称:mangafox,代码行数:20,代码来源:MainActivity.java

示例8: getWebResourceResponse

import android.webkit.WebResourceResponse; //导入依赖的package包/类
/**
 * 获取本地资源
 */
@Nullable
private WebResourceResponse getWebResourceResponse(String url) {
    try {
        // 如果是图片且本地有缓存
        if (isImageSuffix(url) || isGifSuffix(url)) {
            FileInputStream inputStream = mCache.getStream(url);
            if (null != inputStream) {
                return new WebResourceResponse(getMimeType(url), "base64", inputStream);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:GcsSloop,项目名称:diycode,代码行数:19,代码来源:GcsMarkdownViewClient.java

示例9: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    if (prefs.getBoolean("adblock", true)) {
        boolean ad;
        if (!loadedUrls.containsKey(url)) {
            ad = AdBlocker.isAd(url);
            loadedUrls.put(url, ad);
        } else {
            ad = loadedUrls.get(url);
        }
        return ad ? AdBlocker.createEmptyResource() :
                super.shouldInterceptRequest(view, url);
    }
    return super.shouldInterceptRequest(view, url);
}
 
开发者ID:RiccardoBusetti,项目名称:Colombo,代码行数:17,代码来源:MainActivity.java

示例10: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的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

示例11: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的package包/类
@SuppressLint("NewApi")
public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request) {
    String url = request.getUrl().toString();
    try {
        URL urlData = new URL(url);
        String path = urlData.getPath().substring(1);
        if (!path.endsWith(".js") && !path.endsWith(".css")) {
            return null;
        }
        Log.d("BasicWebViewClient", "Find " + path + " from asset.");
        InputStream localStream = assetMgr.open(path);
        Log.d("BasicWebViewClient", url + " found, try load from asset.");
        return new WebResourceResponse((path.endsWith(".js") ? "text/javascript" : "text/css"), "UTF-8", localStream);
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:vinexs,项目名称:extend-enhance-base,代码行数:18,代码来源:BaseWebViewClient.java

示例12: shouldInterceptRequest

import android.webkit.WebResourceResponse; //导入依赖的package包/类
/**
 * Attempt to retrieve the WebResourceResponse associated with the given <code>url</code>.
 * This method should be invoked from within
 * {@link android.webkit.WebViewClient#shouldInterceptRequest(android.webkit.WebView, String)}.
 *
 * @param url the url to process.
 * @return a response if the request URL had a matching handler, null if no handler was found.
 */
public WebResourceResponse shouldInterceptRequest(String url) {
    PathHandler handler = null;
    Uri uri = parseAndVerifyUrl(url);
    if (uri != null) {
        synchronized (uriMatcher) {
            handler = (PathHandler) uriMatcher.match(uri);
        }
    }
    if (handler == null)
        return null;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return new WebResourceResponse(handler.getMimeType(), handler.getEncoding(),
                new LegacyLazyInputStream(handler, uri));
    } else {
        InputStream is = handler.handle(uri);
        return new WebResourceResponse(handler.getMimeType(), handler.getEncoding(),
                is);
    }
}
 
开发者ID:google,项目名称:webview-local-server,代码行数:29,代码来源:WebViewLocalServer.java

示例13: testHostAssets

import android.webkit.WebResourceResponse; //导入依赖的package包/类
public void testHostAssets() {
    final String testHtmlContents = "<body><div>hah</div></body>";

    WebViewLocalServer assetServer = new WebViewLocalServer(new MockProtocolHandler() {
        @Override
        public InputStream openAsset(String path) throws IOException {
            if (path.equals("/www/test.html")) {
                return new ByteArrayInputStream(testHtmlContents.getBytes("utf-8"));
            }
            return null;
        }
    });

    WebViewLocalServer.AssetHostingDetails details =
            assetServer.hostAssets("androidplatform.net", "/www", "/assets", true, true);
    assertEquals(details.getHttpPrefix(), Uri.parse("http://androidplatform.net/assets"));
    assertEquals(details.getHttpsPrefix(), Uri.parse("https://androidplatform.net/assets"));

    WebResourceResponse response =
            assetServer.shouldInterceptRequest("http://androidplatform.net/assets/test.html");
    assertNotNull(response);
    assertEquals(testHtmlContents, readAsString(response.getData(), "utf-8"));
}
 
开发者ID:google,项目名称:webview-local-server,代码行数:24,代码来源:WebViewLocalServerTest.java

示例14: loadFromAssets

import android.webkit.WebResourceResponse; //导入依赖的package包/类
private WebResourceResponse loadFromAssets(
        String url, String assetPath,
        String mimeType, String encoding
) {

    AssetManager assetManager = this.activity.getAssets();
    InputStream input = null;
    try {
        Log.d(LOG_TAG, "Loading from assets: " + assetPath);


        input = assetManager.open("/images/logo.png");
        WebResourceResponse response =
                new WebResourceResponse(mimeType, encoding, input);

        return response;
    } catch (IOException e) {
        Log.e("WEB-APP", "Error loading " + assetPath + " from assets: " +
                e.getMessage(), e);
    }
    return null;
}
 
开发者ID:jjhesk,项目名称:slideSelectionList,代码行数:23,代码来源:WebviewIntercept.java

示例15: shouldInterceptRequest

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

    String strMimeType = getFileMimeType(request.getUrl().toString());
    if (strMimeType != null)
    {
        String lowerCaseUrl = strMimeType.toLowerCase();
        if (lowerCaseUrl.contains("png") || lowerCaseUrl.contains("jpg") || lowerCaseUrl.contains("jpeg"))
        {
            return handleImageRequest(aWebView, request, strMimeType);
        }
    }

    return super.shouldInterceptRequest(aWebView, request);
}
 
开发者ID:kercer,项目名称:kerkee_android,代码行数:18,代码来源:KCWebViewClient.java


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