Search code examples
javaandroidandroid-webviewandroid-13

Image content not loading(images are broken) on WebView after support to Android 13


I have one legacy application for the emails. The issue is Image content not loading properly post support to android 13 on web view for Android 10 and above, it works well below android 10.

This is how the content is loaded: webView.loadDataWithBaseURL("file:///android_asset/", html, mMime, mEncoding, null);

assests folder consists .js and .css files with some icons files (.png) as shown in SS. Assest folder

And this is how the html content is processed html content

The following settings to web view are already set but it's not working:

                webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        webView.getSettings().setAllowContentAccess(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NORMAL);
        webView.getSettings().setLoadsImagesAutomatically(true);
                webView.getSettings().setAllowFileAccessFromFileURLs(true);
        webView.getSettings().setAllowUniversalAccessFromFileURLs(true);

I have already tried as per the official documentation but no luck!

Current Output: Mail details screen with broken images

Mail details screen with broken images


Solution

  • This issue is resolved. Changes according to the below piece of code work well with the Image loading and as desired.

    webView.loadDataWithBaseURL("https://yourdomain.com/", html, mMime, mEncoding, null);