Search code examples
androidwebviewresourcesimageviewdrawable

Load resources image to webview


I've problem with packing images for my application. I've raw folder in my project. The folder contains images in jpg, like img1.jpg, img2.jpg. I need to view these files in WebView in my application.

I try

String Url="file:///android_res/raw/"+neccessary_file";
WebView.LoadUrl(Url);

When i try application webview send 404 Page, file not found. What can i do for correct?


Solution

  • Try to append your URL with

    String html = "<html><head></head><body><img src=\""+ URL + "\"></body></html>";
    webView.loadDataWithBaseURL("", html, "text/html","utf-8", ""); 
    

    Also Refer this link https://stackoverflow.com/a/14405801/1208563