Patrick
Patrick

Reputation: 11

How to add image to html from sd card

I have an html file. I show it as webview. I tried to add image on it from sd but i couldn't. Here is the code i used:

<tr height="21" style='height:15.75pt'>
    <td height="21" class="xl71" style='height:15.75pt'>&nbsp;</td>
    <td class="borderLeft">&nbsp;</td>
    <td>&nbsp;</td>
    <td>
    <![if !vml]>
      <span style='mso-ignore:vglayout;add
  position:absolute;z-index:20;margin-left:24px;margin-top:3px;width:73px;
  height:144px'><img src="/sdcard/SurucuImza.jpg" alt="" width="168" height="120"       v:shapes="Picture_x0020_421" /></span>
      <![endif]>
      <span
  style='mso-ignore:vglayout2'>
        <table cellpadding="0" cellspacing="0">
          <tr>

I have used the path here:

<img src="/sdcard/SurucuImza.jpg" alt="" width="168" height="120" v:shapes="Picture_x0020_421" />

But it didn't work. I can't show the image. Do you have any idea?

Upvotes: 0

Views: 1740

Answers (4)

Avi
Avi

Reputation: 1

Use

src="file:///" + Environment.getExternalStorageDirectory() + "your_image_folder_name/SurucuImza.jpg"

insteed of

src="/sdcard/SurucuImza.jpg"

NOTE: give the permission to manifest first..

android.permission.WRITE_EXTERNAL_STORAGE 
android.permission.READ_EXTERNAL_STORAGE

Upvotes: 0

SpongePablo
SpongePablo

Reputation: 890

First thing i would do... is to copy the image into your working directory. If you dont do that, when you remove your SD card... you can say goodbye to your picture.

In case that this is not possible, just put the full path to that place.

Upvotes: 0

Stephane Mathis
Stephane Mathis

Reputation: 6622

Try with "file://mnt/sdcard/SurucuImza.jpg". You might need to allow th access with this line : mWebView.getSettings().setAllowFileAccess(true);

Upvotes: 0

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132982

try as

    String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
    String imagePath = "file:/"+ base + "/SurucuImza.jpg";
    String strimg="<img src=\""+ imagePath + "\" alt=\"\" width=\"168\" height=\"120\" v:shapes=\Picture_x0020_421\" />";

Upvotes: 2

Related Questions