Android 如何从sd卡向html添加图像
我有一个html文件。我将其显示为webview。我试图从sd向其添加图像,但无法。 以下是我使用的代码:Android 如何从sd卡向html添加图像,android,Android,我有一个html文件。我将其显示为webview。我试图从sd向其添加图像,但无法。 以下是我使用的代码: <tr height="21" style='height:15.75pt'> <td height="21" class="xl71" style='height:15.75pt'> </td> <td class="borderLeft"> </td> <td&
<tr height="21" style='height:15.75pt'>
<td height="21" class="xl71" style='height:15.75pt'> </td>
<td class="borderLeft"> </td>
<td> </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>
我使用了以下路径:
<img src="/sdcard/SurucuImza.jpg" alt="" width="168" height="120" v:shapes="Picture_x0020_421" />
但它不起作用。我无法显示图像。
你有什么想法吗?试试看
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\" />";
String base=Environment.getExternalStorageDirectory().getAbsolutePath().toString();
字符串imagePath=“文件:/”+base+“/SurucuImza.jpg”;
字符串strimg=“”;
尝试使用“file://mnt/sdcard/SurucuImza.jpg".
您可能需要使用以下行允许th访问:
mWebView.getSettings().setAllowFileAccess(true) 我要做的第一件事。。。是将映像复制到您的工作目录中。如果你不这样做,当你取出SD卡时。。。你可以和你的照片说再见了 如果不可能,只需将完整路径放到该位置。使用
src="file:///" + Environment.getExternalStorageDirectory() + "your_image_folder_name/SurucuImza.jpg"
代替
src="/sdcard/SurucuImza.jpg"
注意:首先授予显示权限。
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE
动态路径很重要。