【发布时间】:2015-05-08 06:56:35
【问题描述】:
我有这样的功能:
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (url.contains("images/srpr/logo11w.png")){
return new WebResourceResponse("text/plain", "utf-8",
new ByteArrayInputStream("".getBytes()));
}
return super.shouldInterceptRequest(view, url);
}
它正在工作,很好。我想通过当前的 webView url 添加一项检查,并仅在特定页面上拦截请求。而当做出这种声明时:
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (url.contains("images/srpr/logo11w.png") && webView.getUrl().contains("google.lt")){
return new WebResourceResponse("text/plain", "utf-8",
new ByteArrayInputStream("".getBytes()));
}
return super.shouldInterceptRequest(view, url);
}
应用程序崩溃。有人可以帮助我,并告诉我我做错了什么吗?
编辑:添加日志。
1689-1731/com.application.webview W/WebView﹕ java.lang.Throwable: A WebView method was called on thread 'Thread-102'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {527c3a60} called on null, FYI main Looper is Looper (main, tid 1) {527c3a60})
at android.webkit.WebView.checkThread(WebView.java:2072)
at android.webkit.WebView.getUrl(WebView.java:1229)
at com.application.webview.fragment.MainFragment$3.shouldInterceptRequest(MainFragment.java:452)
at com.android.webview.chromium.WebViewContentsClientAdapter.shouldInterceptRequest(WebViewContentsClientAdapter.java:283)
at com.android.org.chromium.android_webview.AwContents$IoThreadClientImpl.shouldInterceptRequest(AwContents.java:244)
at dalvik.system.NativeStart.run(Native Method)
05-08 03:12:12.023 1689-1731/com.application.webview W/System.err﹕ java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'Thread-102'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {527c3a60} called on null, FYI main Looper is Looper (main, tid 1) {527c3a60})
05-08 03:12:12.027 1689-1731/com.application.webview W/System.err﹕ at android.webkit.WebView.checkThread(WebView.java:2082)
05-08 03:12:12.031 1689-1731/com.application.webview W/System.err﹕ at android.webkit.WebView.getUrl(WebView.java:1229)
05-08 03:12:12.035 1689-1731/com.application.webview W/System.err﹕ at com.application.webview.fragment.MainFragment$3.shouldInterceptRequest(MainFragment.java:452)
05-08 03:12:12.043 1689-1731/com.application.webview W/System.err﹕ at com.android.webview.chromium.WebViewContentsClientAdapter.shouldInterceptRequest(WebViewContentsClientAdapter.java:283)
05-08 03:12:12.047 1689-1731/com.application.webview W/System.err﹕ at com.android.org.chromium.android_webview.AwContents$IoThreadClientImpl.shouldInterceptRequest(AwContents.java:244)
05-08 03:12:12.051 1689-1731/com.application.webview W/System.err﹕ at dalvik.system.NativeStart.run(Native Method)
05-08 03:12:12.111 1689-1731/com.application.webview W/System.err﹕ Caused by: java.lang.Throwable: A WebView method was called on thread 'Thread-102'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {527c3a60} called on null, FYI main Looper is Looper (main, tid 1) {527c3a60})
05-08 03:12:12.127 1689-1731/com.application.webview W/System.err﹕ at android.webkit.WebView.checkThread(WebView.java:2072)
05-08 03:12:12.127 1689-1731/com.application.webview W/System.err﹕ ... 5 more
05-08 03:12:12.175 1689-1731/com.application.webview A/libc﹕ Fatal signal 6 (SIGABRT) at 0x00000699 (code=-6), thread 1731 (Chrome_IOThread)
【问题讨论】:
-
你能发布日志消息吗?
-
Gangulia,添加日志
标签: android webview android-webview