Android: loading a large image from assets using Webview

I need to download a large image (approximately 3500 x 3500 pixels) from assets using web browsing.

I did a lot of research here at Stackoverflow, and yet none of the answers worked for me. I believe this could be an issue with Android 4.0+ using assets.

My current code is as follows:

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

test.html looks like this:

 <html> <table> <tr> <td> <img src="testimage.png" width="3500px" alt="TestAlt"> </td> </tr> </table> </html> 

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

The webpage is not available. The webpage in the file: ///android_asset/test.html may be temporarily unavailable or it may be transferred 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
source share
2 answers

Found the answer from here:

fooobar.com/questions/1494095 / ...

 webview.getSettings().setBuiltInZoomControls(true); webview.loadDataWithBaseURL("file:///android_asset/", "<img src='file:///android_res/drawable/example.png' />", "text/html", "utf-8", null); 
+3
source

Alternative method: If you can use the KitKat API 19 API and you control the webview so you don't have to worry about security issues ...

Then:
webSettings.setDomStorageEnabled (true);

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

With these settings, I was able to download information (browser initiated - Javascript) to retrieve file information from the android_asset and SD card folders. Also to save information on SDCard.

If anyone knows how to do the same in V17, what would be great to know !?

0
source

Source: https://habr.com/ru/post/1494094/


All Articles