Display .mht file on android

折月煮酒 提交于 2019-12-29 08:41:43

问题


How to display .mht(MHTML) file on android webview. I tried to open the .mht file on default android browser but that didn't open but i am able to open same on opera mobile browser. So i tried with MHTUnpack java library. I didn't succeed in that.

Here's a link!

Please if anybody has used this MHTUnpack let me how can i use that in android. And also let me know if there is any other library.

Thanks


回答1:


Found this unknown google project which appears to be working.

This utility decodes the mhtml file and save it on given path(internal or external). After saving it returns the html file path which could be loaded into webview.

Try it.




回答2:


After overcoming frustration about WebView.saveWebArchive() format change in Android 4.4, I tried the "unknown google project" Chitranshu Asthana mentioned in his answer, but code provided there is slow (~10s for 1MB *.mht file with a dozen of pictures) and doesn't handle attached file names correctly.

MHT Unpack library combined with Java Mail for Android (not the one provided by Oracle) worked perfectly for me.


EDIT: Fixed the link to MHT Unpack library. Also, here's usage example:

// contentPath - path to input .mht file
public static String unpackMht(String contentPath) throws IOException {
        // dstPath - path where file will be unpacked
        String dstPath = openTempDir(null) + File.separator;
        String indexFileName = dstPath + new File(contentPath).getName();

        try {
            Collection<Attachment> attachments = MHTUnpack.unpack(new File(contentPath));

            for (Attachment attachment : attachments) {
                String filename = attachment.getFileName();
                String path = filename == null ? indexFileName : dstPath +  filename;
                File newFile = new File(path);
                if (newFile.exists()) {
                    newFile.delete();
                }
                attachment.saveFile(path);
            }

            return indexFileName;
        } catch (MessagingException e) {
            throw new IOException(e);
        }
    }


来源:https://stackoverflow.com/questions/11556059/display-mht-file-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!