简体   繁体   中英

android webview loading images

I have looked at 50+ sources, none give the exact information

loading html into webview with images in the code does make webview load the images, only when it exists in the assets

I can make webview show images from other sites as well

I am creating images dynamically, and I want to show them in the webview

I cannot copy files to the assets folder, so I cannot load them from there either

It is as if it is carefully planned to prevent a very specific functionality that I am striving for.

There are many answers providing solutions, none do work, and they are from many years ago.

I want to load files that exist in the getFilesDir(); directory, because they are created there.

I'd appreciate help, thank you.

I have tried

all these:

webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowContentAccess(true);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);

& many many combinations of URLS trying to access the file at getFilesDir(); in the HTML code none work except for loading from other sites, and from assets which I cannot write to.

I can add images directly into HTML by calculating the base64 string of a image and adding the HTML tag+code/url:

<img src="data:image/jpg;base64,######base64string#######">

how you generate the base 64 string is up to you. I am still searching for a method to make webview load images from the getFilesDir();, the working directory of my app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM