广告在HoneyComb Webview上显示但不在ICS Webview上显示

时间:2012-03-08 16:35:12

标签: android-3.0-honeycomb android-webview android-4.0-ice-cream-sandwich ads

我已经调整了我的Honeycomb应用程序来处理ICS。一切都很好除了我在webview中的广告不再显示。我没有对此部分进行任何代码更改。 ICS兼容代码在HoneyComb设备上显示广告,但不在ICS设备上显示。有什么不同,我该如何处理?

以下是我在ICS设备上收到的日志,但不是HoneyComb或更低版本的日志:

03-08 14:50:42.485: W/webview(24262): java.lang.Throwable: Warning: A WebView method was called on thread 'Thread-617'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
03-08 14:50:42.485: W/webview(24262):   at android.webkit.WebView.checkThread(WebView.java:9468)
03-08 14:50:42.485: W/webview(24262):   at android.webkit.WebView.getSettings(WebView.java:4143)
03-08 14:50:42.485: W/webview(24262):   at com.accuweather.android.tablet.ads.AdView$2.run(AdView.java:160)
03-08 14:50:42.495: W/System.err(24262): java.io.IOException: java.net.URISyntaxException: Invalid % sequence: %wl in query at index 138: http://www.accuweather.com/adrequest/adrequest.asmx/getAdCode?strAppID=lenovo&strPartnerCode=lenovo&strIpAddress=fe80::42fc:89ff:fe93:9fcb%wlan0&strUserAgent=Mozilla%2F5.0+%28Linux%3B+U%3B+Android+4.0.3%3B+en-us%3B+Xoom+Build%2FIML77%29+AppleWebKit%2F534.30+%28KHTML%2C+like+Gecko%29+Version%2F4.0+Safari%2F534.30&strCurrentZipCode=cityId=335315&strWeatherIcon=12&strUUID=99000052310400
03-08 14:50:42.495: W/System.err(24262):    at libcore.net.http.HttpEngine.<init>(HttpEngine.java:194)
03-08 14:50:42.495: W/System.err(24262):    at libcore.net.http.HttpURLConnectionImpl.newHttpEngine(HttpURLConnectionImpl.java:256)
03-08 14:50:42.495: W/System.err(24262):    at libcore.net.http.HttpURLConnectionImpl.initHttpEngine(HttpURLConnectionImpl.java:243)
03-08 14:50:42.495: W/System.err(24262):    at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:78)
03-08 14:50:42.495: W/System.err(24262):    at com.accuweather.android.tablet.ads.AdView$AdRequest.getInputStreamFromURL(AdView.java:345)
03-08 14:50:42.495: W/System.err(24262):    at com.accuweather.android.tablet.ads.AdView$AdRequest.makeRequest(AdView.java:293)
03-08 14:50:42.495: W/System.err(24262):    at com.accuweather.android.tablet.ads.AdView$2.run(AdView.java:159)
03-08 14:50:42.495: W/System.err(24262): Caused by: java.net.URISyntaxException: Invalid % sequence: %wl in query at index 138: http://www.accuweather.com/adrequest/adrequest.asmx/getAdCode?strAppID=lenovo&strPartnerCode=lenovo&strIpAddress=fe80::42fc:89ff:fe93:9fcb%wlan0&strUserAgent=Mozilla%2F5.0+%28Linux%3B+U%3B+Android+4.0.3%3B+en-us%3B+Xoom+Build%2FIML77%29+AppleWebKit%2F534.30+%28KHTML%2C+like+Gecko%29+Version%2F4.0+Safari%2F534.30&strCurrentZipCode=cityId=335315&strWeatherIcon=12&strUUID=99000052310400
03-08 14:50:42.495: W/System.err(24262):    at libcore.net.UriCodec.validate(UriCodec.java:58)
03-08 14:50:42.495: W/System.err(24262):    at java.net.URI.parseURI(URI.java:406)
03-08 14:50:42.495: W/System.err(24262):    at java.net.URI.<init>(URI.java:204)
03-08 14:50:42.495: W/System.err(24262):    at java.net.URL.toURILenient(URL.java:510)
03-08 14:50:42.495: W/System.err(24262):    at libcore.net.http.HttpEngine.<init>(HttpEngine.java:192)
03-08 14:50:42.495: W/System.err(24262):    ... 6 more

2 个答案:

答案 0 :(得分:3)

ICS WebView实施进行了改进,因此我们很多人都遇到了ICS前和ICS WebView行为的问题。

看起来你有两个问题。

首先,您要对查询进行编码,因为看起来您无法传递在HTML转义中具有特殊含义的“%”。它看起来像是在strIpAddress参数中发生的。您可以使用以下代码:

String encodedIPAddress = URLEncoder.encode(strIpAddressValue);

我会编码每个参数值,然后使用String.format或String +将它们全部放在最终的URL字符串中。通过这种方式,您可以避免任何未来类似的问题。

其次,Android抱怨你没有从UI线程调用WebView。我会把你在runInUiThread中调用的方法(我假设你称之为showAd())包装起来,如下所示:

activity.runOnUiThread(new Runnable() {
   public void run() {
      webView.showAd();
   }
});

答案 1 :(得分:0)

在我的情况下,我在Activity.runOnUiThread(Runnable runnable)中有以下行。

webView.setWebChromeClient(WebChromeClient webChromeClient);

显示进度表。

当我注释掉该行时,应用程序停止显示

你提到的错误。