在android上显示.mht文件



如何在android webview上显示.mht(MHTML)文件。我试图在默认的android浏览器上打开.mht文件,但没有打开,但我可以在opera移动浏览器上打开。所以我尝试了MHTUnpack java库。我没有成功。

这里有一个链接!

如果有人使用过这个MHTUnpack,请告诉我如何在android中使用它。还请告诉我是否还有其他图书馆。

感谢

发现这个未知的谷歌项目似乎正在运行。

该实用程序解码mhtml文件并将其保存在给定的路径(内部或外部)上。保存后,它返回可以加载到webview中的html文件路径。

试试看。

在克服了Android 4.4中WebView.saveWebArchive()格式更改的挫折后,我尝试了Chitranshu Asthana在回答中提到的"未知谷歌项目",但提供的代码速度很慢(对于有十几张图片的1MB*.mht文件,大约10秒),并且无法正确处理附加的文件名。

MHT Unpack库与Java Mail for Android(不是Oracle提供的)相结合非常适合我。


编辑:修复了指向MHT Unpack库的链接。此外,这里还有一个用法示例:

// 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);
        }
    }

最新更新