X
X
xaiponews2020-12-31 16:01:12
Android
xaiponews, 2020-12-31 16:01:12

How to open local html file in webview?

The application saves the web page archive in the html file. If you click in Android studio Copy Path, then the file is located here in the phone's memory /data/data/com.example.example/files/archiv.html"

How to open the saved archiv.html file in webviwe

Not working options:

webview.loadUrl(" file :///data/data/com.example.example/files/archiv.html ");

File file = new File("/data/data/com.example.example/files/archiv.html");
webView. loadUrl("file://" + file);

The option of uploading a file to the program project to the asset folder is not suitable, since the file is saved on the device after compilation and cannot be transferred to the project.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2020-12-31
@402d

File file = new File("/data/data/com.example.example/files/archiv.html");
webView.loadUrl("file://" + file);

here is nonsense, at least look at the message about a file not found.
Read the contents of the file into a string and then
webView.loadData(currentHTML, "text/html; charset=utf-8", "utf-8");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question