【问题标题】:Assets image to Internal storage runtime资产图像到内部存储运行时
【发布时间】: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??

我尝试将图像从资产文件夹复制到内部存储代码,但这对我不起作用。

【问题讨论】:

    标签: android html


    【解决方案1】:

    你的url 不完整,你需要它以file:// 开头,所以整个事情就是

    file:///data/data/com.tek.teksmartlab/app_images/image1.jpg
    

    【讨论】:

    • 是的,但这也不能解决问题,因为 file:/// 基本上会检查应用程序的资产,在我的例子中是 HTML 查看器。因此,我们需要提取图像并将它们存储在一些内部存储中。我们如何做到这一点?正如我所说,我已经在线检查了代码,但没有帮助。
    猜你喜欢
    • 2020-11-26
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    • 2013-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    相关资源
    最近更新 更多