After processing the file, I get an HTML string in which the image is set as
<img src="abc.001.png" width="135" height="29" alt="" style="margin-left:0pt; margin-top:0pt; position:absolute; z-index:-65536" />
The path to the image should not be changed, because I have to select a file element from the list. The image is in the same directory as the file. I am loading an HTML string using loadData / loadDataWithBaseURL but the image is not showing. I see only its frame.
How can i fix this? And can I apply this solution if I have many images indexed as .001.jpg, .002.png, etc. (Everything in the catalog)?
Update: thanks, it works with the loadUrl () operator no matter what I call the image. In fact, I have to read and process the content before uploading it to WebView. Therefore, I use the loadDataWithBaseUrl () statement and get the problems above. Here is my code in a test project for reading and displaying the contents of Test.html.
String res = "";
File file = new File(Environment.getExternalStorageDirectory()+"/Test.html");
try {
FileInputStream in = new FileInputStream(file);
if (in != null) {
BufferedReader buffreader = new BufferedReader(
new InputStreamReader(in));
String line;
while ((line = buffreader.readLine()) != null) {
res += line;
}
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
wv.loadDataWithBaseURL(null, res, "text/html", "utf-8", null);
The statement in // works, but that’s not what I can do in my real project. I have a solution: after processing the content, I have to save it in a temporary HTML file, and then upload it, this file will be deleted later. However, I am still waiting for a better solution :)
source
share