There is a line <p style="text-align: center;"><img src="images/izvestnye/img1.jpg" alt="Image 1" /></p> , which I submit to the input in WebView. But before displaying this picture, I substitute in the link the domain of the site in this way

 if (img.contains("<img src=\"images")) { img = img.replaceAll("<img src=\"images", "<img src=\"https://site.ru/images"); } 

Everything works .. But the question is whether it is possible to display a picture, regardless of the https or http protocol? Or you can not do that?

    1 answer 1

    Since you are submitting the page itself as a string to WebView, links to images and other things cannot be relative. Only absolute.

    Alternatively, you can load pictures from assets, for example:

     String sHtmlTemplate = "<html><head></head><body><img src=\"file:///android_asset/my_pic.png\"></body></html>"; webView.loadDataWithBaseURL(null, sHtmlTemplate, "text/html", "utf-8",null); 

    Accordingly, my_pic.png should be in assets at the root.

    Added:
    It occurred to me, I never used it myself, try this:

     webView.loadDataWithBaseURL("https://site.ru/", myHtmlWithImg, "text/html", "utf-8", null); 

    The same method is intended for such cases to substitute the basis for relative references.

    • Thank you, but this approach is not suitable. I am loading data from the site. But thanks for the reply. - Kolhoznik