0

I am facing an issue in WebView in devices running API 27 (8.1.0).

I pass off my params in the userAgentString based on which a php page loads the appropriate data. When I open the WebView for the first time it works well.

However, whenever I open the WebView after this first time (I call setUserAgentString each time I load it, with fresh values), it persists with that old value of userAgentString, thus not loading the correct data. This happens irrespective of whether I am in the same activity and re-using the same WebView, or move to a different activity where a new instance of WebView is used.

The following devices gave this odd behaviour -

  1. Google Pixel 2XL, version 8.1.0
  2. Xiaomi Mi A1, version 8.1.0

...and the webview was working perfectly on the following devices, not showing this behaviour -

  1. Samsumg GALAXY Tab SM-T825, version 8.0.0
  2. Moto G4, version 7.0.0
  3. HTC Desire 526, version 4.4.2

I think this could be linked with how the Android Webview implementation has been changed to Chrome in Oreo.

However, the behaviour did not change irrespective of what I set as "Webview Implementation" in Developer settings, implying that may not be the cause.

Additionally, only when I clear data, or do a fresh install, is the userAgentString value reset.

I have read dozens of posts on SO, and tried all sorts of methods related to WebView and WebSettings, but I haven't managed to find a solution.

What am I missing here?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Possible duplicate? https://stackoverflow.com/questions/51784469/android-oreo-webview-renders-layout-too-small-after-2nd-loading – GhostCat Aug 15 '18 at 09:23
  • Please compare the dates of the questions to decide which question is a duplicate of whom. The link you have given is a duplicate of this question, not the other way around. – Yuganka Sharan Aug 16 '18 at 07:27

2 Answers2

0

Maybe, this code can help you.

webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setAppCacheEnabled(false);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

Lucky :)

jsancheh
  • 54
  • 1
  • 3
0

I experienced this issue recently and the problem was that the device had an outdated Chrome WebView framework. Simply update it via the Play Store and the issue should resolve.

najm
  • 834
  • 1
  • 13
  • 32