2

My app uses a WebView widget to load ads from Google AdManager. AdManager gives you an HTML snippet, which is 90% JavaScript to call their server for the image to load.

  1. I put their html snippet into a string and use String.format to add in several variables that AdManager requires.
  2. I enable JavaScript on the WebView (webView.getSettings().setJavaScriptEnabled(true);)
  3. I load the string into the WebView (webView.loadData(myString, "text/html", "UTF-8");

result: the ad never loads (although the WebViewClient shows several .js resources loading).

If I take that exact string and create a file and then use webView.loadUrl("file:///android_asset/test.html"), the image loads properly.

Why would loadUrl work but loadData does not?

BTW, I've verified that JavaScript is running. I injected a little script to write out a text string and it works.

1 Answer 1

1

There is a bug in WebView that's been there since about 1.5. Try using this line instead and see if it works for you.

webView.loadDataWithBaseURL("fake://fake.com", myString, "text/html", "UTF-8", null);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.