从控制台中打开HTML文件控制台、文件、HTML

2023-09-06 10:41:07 作者:黑白颠倒的年华

我们已经取得了从服务器读取普通数据并撰写HTML文件bash脚本。该文件被创建精,我们只需要在浏览器中打开它。

We've made a bash script that read plain data from a server and compose a html file. The file is created fine, and we just need to open it in a browser.

这任务是比我们预期的更困难。

This task is more difficult than we have expected.

能否请您给我们介绍一下如何实现它的一些建议吗?

Could you please give us some advice about how to achieve it?

这如果我们到目前为止已经完成的:

This if what we've done so far:

am start -a android.intent.action.VIEW http:///storage/sdcard0/path/final.html -t text/html

这code启动一个对话框来选择浏览器,但它试图找到在互联网上的资源。当我们将的http:/// 的file:/// 设备尝试打开该文件没有运气

This code launches a dialog to select the browser, but it tries to locate the resource in internet. When we replace http:/// by file:/// the device tries to open the file with no luck.

我们读过其他一些关于这个话题的问题,但我们能够从浏览器直接打开该文件。我们的问题是如何从早上打开它。

We've read some others questions about this topic, but we're able to open the file directly from the browser. Our problem is how to open it from am.

不知道如何做到这一点?

Any idea how to accomplish this?

推荐答案

首先,让我把一个插头 Jsoup 用于获取和分析现有的HTML和创建新的HTML ...只是有一堆提供。

First, let me put in a plug for Jsoup for getting and parsing existing HTML and for creating new HTML... just has a bunch to offer.

其次,你需要使用 loadDataWithBaseUrl 从web视图类,像这样:

Second, you'll want to use loadDataWithBaseUrl from the WebView class like so:

webview.loadDataWithBaseURL(文件:/// android_asset /,thingToLoadAsHtml,text / html的,UTF-8,关于:空白)

其中thingToLoadAsHtml是在它所有的HTML的字符串。

where thingToLoadAsHtml is a String with all the HTML in it.

查看 Android开发者文档获取更多信息。