Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView on Android 11 - not showing local image files

I have a problem with WebView on Android 11 (this worked under Android 10). The html

<img src='file:///storage/emulated/0/Android/data/<package>/image_cache/item_15.bmp'>

does not load the image. That html is part of a larger string. The image file was created by the same app and is valid.

What's changed?

like image 983
Kevin Gilbert Avatar asked Oct 27 '25 06:10

Kevin Gilbert


1 Answers

Try setting webview.getSettings().setAllowFileAccess(true);. The documentation says:

The default value is true for apps targeting Build.VERSION_CODES.Q and below, and false when targeting Build.VERSION_CODES.R and above.

like image 105
rakesh Avatar answered Oct 28 '25 22:10

rakesh