0

I have an app that shows a full screen svg image in a WebView. Everything works perfectly fine in my Android 4.2 test device and in the emulator. However in Android 4.4 the svg image just shows up as a broken image.

Does anyone have a fix for this problem or know why it is happening? Thanks.

    browser=(ClickableWebView)view.findViewById(R.id.my_browser);
    browser.setWebViewClient(new WebViewClient());
    browser.getSettings().setBuiltInZoomControls(true);
    browser.getSettings().setRenderPriority(RenderPriority.HIGH);
    browser.getSettings().setDisplayZoomControls(false);
    browser.getSettings().setLoadWithOverviewMode(true);
    browser.getSettings().setJavaScriptEnabled(true); 

    url = "<html><body style=\"margin: 0; padding: 0 \"><table align=\"center\"   cellpadding=0 cellspacing=0 style=\"height:100%; width:100%; \"><tr><td align=\"center\" style=\"vertical-align:middle;\"><img src=\"file:///android_res/drawable/" + filename + ".svg\" height=\"" + height + "\"/><br><font size=\"0\">.</font></td></tr></table></body></html>";

    browser.loadDataWithBaseURL(url, url, "text/html", Encoding.UTF_8.toString(), url);
Projectile Fish
  • 935
  • 3
  • 9
  • 26
  • Isn't this your problem and answer? http://stackoverflow.com/questions/18356098/having-issue-on-real-device-using-vector-image-in-android-svg-android/18358672#18358672 – Robert Longson Jun 24 '14 at 05:19
  • Not really. I'm not using a svg parser, just a webview to display the svg like you would a jpg or png. Anyway I tried to disable hardware acceleration on the webview, but it has no effect on the problem. – Projectile Fish Jun 24 '14 at 06:22

1 Answers1

1

Okay so after some playing around i've managed to fix it.

For some reason on Android 4.4, svg images must be stored in the assets folder (file:///android_asset/). On previous Android versions it was fine to store svgs in the drawable folders but it seems this is not the case anymore.

Projectile Fish
  • 935
  • 3
  • 9
  • 26
  • I spent few hours searching the reason why my icons don't show up in my WebView. I was looking everywhere. Then I found this short answer with 0 upvotes. Thanks man, you helped me a lot. – Chamov Feb 11 '19 at 00:06