简体   繁体   中英

Android WebView rendered incorrectly on LG G2

I am writing an app for our client in which I must show a WebView to the user which is a web site supplied by the client in which I inject JS in order to hide certain desktop-only elements.

I initially ran into a problem on KitKat while attempting to include photos, as the change to the WebChromeClient in KitKat was not updated to handle the component correctly. I was able to solve that problem by implementing the AdvnacedWebView located here and hardcoding the input fields for my project: https://github.com/delight-im/Android-AdvancedWebView

The problem I am running into now is the web page is rendered incorrectly when viewed on my Sprint LG G2, but fine on all other devices I have tested on (AT&T LG G3, Nexus 7 2013, Nexus 7 2012, Nexus 9, HTC One V, Samsung Galaxy S3 Mini)

From my assumption based on my LogCat, it appears as though the WebView is attempting to call methods which are not included in the LG G2's version of Android KitKat. It looks like it's attempting to call to Android L.

LogCat: http://pastebin.com/h6mGdNsh

So my question is: is there a reason the web page is being rendered incorrectly on the LG G2, and how would I go about fixing this?

Thanks Adam

The AdvancedWebView is doing a build -dependent check like this:

if (Build.VERSION.SDK_INT >= 21) {
     webSettings.setMixedContentMode(allowed ? WebSettings.MIXED_CONTENT_ALWAYS_ALLOW : WebSettings.MIXED_CONTENT_NEVER_ALLOW);
}

Make sure your target API is set appropriately for this - it could be that all the other devices are also trying to hit 5.0+ APIs, but their fallback behavior is different.

I realized that the WebView was rendering the web page as its desktop version, not as the mobile version. Once I set the User Agent of the WebView to a known good User Agent it worked as expected.

webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.4.2) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM