2

I want show html in text,but images not load.when save text in html file in asset folder images is display.

String html="<html><head></head><body> <Marquee><img src="\mnt\sdcard\osVodigi\Images\apps.png"/><img src="\mnt\sdcard\osVodigi\Images\shop.png"/><img src="\mnt\sdcard\osVodigi\Images\skype.png"/><img src="\mnt\sdcard\osVodigi\Images\word.png"/></marquee>sfdfsd</body></html>";
web.loadData(html, "text/html", "utf-8");

How I Resolve Problms? thanks

Farzad
  • 212
  • 2
  • 6
  • 19

1 Answers1

6

You need to get the path of image and then use the image path in html and load it in webview.

Don't use hard coded path use Environment.getExternalStorageDirectory().

Also check if sdcard is mounted

 if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
 {
       //dosomething
 }  

To get the path and load image in webview

File f= new File(Environment.getExternalStorageDirectory(),"MyFolder"); 
String filename ="image.png" 
String imagePath = "file://"+ f.getAbsolutePath() + File.separator + filename;
String html = "<html><head></head><body><Marquee><img src=\"" + imagePath + "\">My Scroll Text</Marquee></body></html>";
wv= (WebView) findViewById(R.id.wv);
wv.loadDataWithBaseURL("", html, "text/html", "utf-8", "");

Add permission in manifest file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Snap shot. The image and the text does scroll

enter image description here

Raghunandan
  • 132,755
  • 26
  • 225
  • 256