4

I need to load a large image (roughly 3500 x 3500 pixels) from assets using a webview.

I've done a lot of research here on Stackoverflow, and yet, none of the answers have worked for me. I figure it might be an issue with Android 4.0+ using assets.

My current code looks like:

WebView webView = (WebView)findViewById(R.id.myWebView);
webView.loadUrl("file:///android_asset/test.html");

test.html looks like:

<html>

  <table>

    <tr>

      <td>

        <img src="testimage.png" width="3500px" alt="TestAlt">

      </td>

    </tr>

  </table>

</html>

Both testimage.png and test.html are in the assets. Upon testing this on my physical Android device I get:

Webpage not available The webpage at file:///android_asset/test.html might be temporarily down or it may have moved permanently to a new web address.

Logcat as requested:

I/webclipboard: clipservice:       android.sec.clipboard.ClipboardExManager@43ac41b0
V/webkit: BrowserFrame constructor:  this=Handler (android.webkit.BrowserFrame) {43ac3dc8}
D/WebView: loadUrlImpl: called
D/webcore: CORE loadUrl: called
D/webkit: Firewall not null
D/webkit: euler: isUrlBlocked = false
D/chromium: Unknown chromium error: -6
I/GATE: <GATE-M>DEV_ACTION_ERROR</GATE-M>
V/webkit: reportError errorCode(-1) desc(There was a network error)
I/GATE: <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
I/Adreno200-EGLSUB: <ConfigWindowMatch:2136>: Format RGBA_8888.
D/WebView: onSizeChanged - w:480 h:0
D/WebView: onSizeChanged - w:480 h:446
4

2 回答 2

3

Found the answer from here:

https://stackoverflow.com/a/7480245/2060140

webview.getSettings().setBuiltInZoomControls(true);
webview.loadDataWithBaseURL("file:///android_asset/", "<img src='file:///android_res/drawable/example.png' />", "text/html", "utf-8", null);
于 2013-08-07T13:44:16.200 回答
0

另一种方法:如果您能够使用 KitKat API 级别 19,并且您可以控制 Webview,因此无需担心安全问题...

然后:
webSettings.setDomStorageEnabled(true);

webSettings.setAllowFileAccessFromFileURLs(true); webSettings.setAllowUniversalAccessFromFileURLs(true);

通过这些设置,我能够加载信息(由浏览器启动 - Javascript)以从 android_asset 文件夹和 SD 卡中获取文件信息。还可以将信息保存到 SDCard。

如果有人知道如何在 V17 中使同样的事情工作,那将是很高兴知道!?

于 2014-05-19T20:31:57.303 回答