【发布时间】:2015-11-16 16:31:25
【问题描述】:
我已将 docx 转换为 html 并能够在带有图像的 webview 中显示它。但是,当我尝试将从 webview 提取的 html 保存到内部存储时,图像不可见,而是在保存的 html 文件中留下空白。
执行此操作的代码如下:
view = (WebView) findViewById(R.id.webpage);
final long startTime = System.currentTimeMillis();
final long endTime;
try {
final LoadFromZipNG loader = new LoadFromZipNG();
WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage)loader.get(new FileInputStream(new File(Environment.getExternalStorageDirectory()+"/"+getIntent().getStringExtra("textReportFileName"))));
String IMAGE_DIR_NAME = "images";
String baseURL = this.getDir(IMAGE_DIR_NAME, Context.MODE_WORLD_READABLE).toURL().toString();
System.out.println(baseURL); // file:/data/data/com.example.HelloAndroid/app_images/
// Uncomment this to write image files to file system
ConversionImageHandler conversionImageHandler = new AndroidFileConversionImageHandler( IMAGE_DIR_NAME, // <-- don't use a path separator here
baseURL, false, this);
Toast.makeText(getApplicationContext(),baseURL,Toast.LENGTH_SHORT).show();
HtmlExporterNonXSLT withoutXSLT = new HtmlExporterNonXSLT(wordMLPackage, conversionImageHandler);
html = XmlUtils.w3CDomNodeToString(withoutXSLT.export());
File filex = new File(Environment.getExternalStorageDirectory()+"/temp/"+getIntent().getStringExtra("textReportFileName").replace("docx","html"));
if(filex.exists()) {
Toast.makeText(getApplicationContext(),"File exists",Toast.LENGTH_SHORT).show();
InputStream iss = new FileInputStream(filex);
int size = iss.available();
byte[] buffer = new byte[size];
iss.read(buffer);
iss.close();
html = new String(buffer);
//html = html.substring(html.indexOf("0\" rows=\"9\">") + 16);
}
else{
}
} catch (Exception e) {
e.printStackTrace();
finish();
} finally {
endTime = System.currentTimeMillis();
}
突出显示的 toast 消息给出输出:file:/data/data/com.tek.teksmartlab/app_images/
最终的 html 文件还包含带有 src = "file:/data/data/com.tek.teksmartlab/app_images/image1.jpg" 的图像标签(类似于表单)
现在我知道路径文件:/data/data/com.tek.teksmartlab/app_images/ 在内部存储中不存在所以HOW DO I SAVE THE IMAGES FROM THIS PATH TO INTERNAL STORAGE??
我尝试将图像从资产文件夹复制到内部存储代码,但这对我不起作用。
【问题讨论】: