當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。