local HTML file not loaded in Chrome for Android - android

Trying to load a local HTML file (SPA including assets, js, css) on Chrome on Android. File is loaded, html seems to be parsed but shows nothing.
When debugging this remotely (USB/adb) I got this error in the console:
Not allowed to load local resource: content://com.huawei.filemanager.share.fileprovider/root/storage/emulated/0/Download/test1/index.html
Basically it seems the file is not loaded at all.
What can be done ? Help, Tx.

Related

load local file in webview ios using http protocol. (Create Webview server in android and iOS)

Is there any way to create the server in android and iOS to run a web-view? I want to run a local HTML file in a web-view with a local-host URL.
I have already searched for this on the following links but could not find any solution.
GCDWebServer
local-http-server-for-ios
Supercharging the Android WebView
Hereby i am sharing the actual scenario :
1) Download ".zip" file from server and save it on application library directory for offline use.
2) ".zip" file contents html and javascript files. It works when the HTML page is simple. But if the HTML references something else, i.e. a JavaScript file also in the library directory (with an absolute path like ), it will fail to load.
3) I need to setup local server in my device, On application launch local server starts and upload the application library directory on local server and then load the content using local host. See below example
Using Library directory path
file:////Users/prince/Library/Developer/CoreSimulator/Devices/75EF3DD7-DFD1-4EDB-9A6B-9FBA60F4D98C/data/Containers/Data/Application/32F774B2-E811-4281-A37A-DC8A5183B7C8/Library/Application%20Support/adededfe6c1c7bd8b5d5adb19861b9e0/Responses/36b8f6a8d6f58d58f117856dc80b0d37/abc.html
Using localhost path
http://localhost:8080/Application%20Support/adededfe6c1c7bd8b5d5adb19861b9e0/Responses/36b8f6a8d6f58d58f117856dc80b0d37/abc.html
Does anyone know why this happens, and how to resolve the issue?

Android Webview : Not allowed to load resource error library project

My Application has custom webviews loading html (react based webpack build) from local assets folder. When I tried to load the webview , I see the error
"Not allowed to load local resource : file:///android_asset/index.html/#/initialize?..."
Please note : the route ("index.html/#/..") added along with the html. If I load the html only, it works fine.
My application has permission to read and write from storage.
I cannot use loadDataWithBaseURL because the 2nd parameter expects a html data.
Sorry - it was a simple issue.
When using react route - the URL should be :
file:///android_asset/index.html#/initialize?...
and not file:///android_asset/index.html/#/initialize?...
Notice the extra '/' after the .html

android webview load html from server and other files from assets

im a new android developer.
My app has WebView which loads lot of data from my site (which has pics, css, JS files).only the html code is updated weekly. other files are almost never changed. so i was thinking of including these static files in android assets, loading only the html from server and other files from assets and cutting down the loading time. how do i do it.
Android WebView Javascript from assets
and as shown in the above solution i cant change the html code to load these from assets because this site will also be accessed by web users.
Is there a way to do this. Thanks in advance..
Firstly you need to have relative paths
<img src="images/someimage.png">
not
<img src="www.mysite.com/images/someimage.png">
Then you need to load the HTML code not using webBrowser, for example like here
And then you can load HTML source into WebBrowser using base URL pointing to your assets like here

Using Pdf.js in Android hybrid app to load local files

I am developing an app for android using Sencha touch and Cordova which needs to load PDF files.I found the Child browser support on PDF is not there for Android.So I decided to use PDF.js.I am using the following line of code to open the PDF file :
window.open(\''+ ROOT_FOLDER+'/app/util/PDFJS/web/viewer.html?file='+ROOT_FOLDER + '<Path to PDF file>\'
ROOT_FOLDER is the local file path URL like file://app/utils.."
But the pdf is not loading in this case and it is throwing an exception like
XMLHttpRequest cannot load file:///android_asset/www/<path to PDF file>. Cross origin requests are only supported for HTTP.
Please let me know how to fix this issue, or how to load PDF files from local location using PDF.js
If you want to load the files from local location, then it should be present in the same folder with viewer.html. In short the PDF should not be outside the main folder where all these html and js files are present.

Unknown Chromium Error -6 when loading local images in Android Webview

I'm working on a Worklight project that downloads a zip file, unpacks it, and stores the files in the specific documents directory of the platform (in iOS that's NSDocumentDirectory, on Android I'm using getFilesDir()). The file consists of one HTML file and several images, located in a sub directory (media). Downloading and unzipping works fine on both platforms. After the unzip process I'm loading the contents of the HTML file into an existing div (since this is a Worklight app, everything is in one HTML file).
Here things become complicated:
The image tag sources in the HTML file that I've downloaded are relative to the HTML file (e.g. 'media/myimage.jpg'). When I inject the HTML file into the Worklight HTML file (which is located in the App bundle/package), the base URL changes and the images can't be found anywhere. I fixed this by writing native functions that rewrite all the image tags in the downloaded HTML file to point to an absolute URL (iOS: /var/mobile/Applications/<identifier>/Documents/, Android: /data/data/<id>/files/). This works fine on iOS, but on Android it causes the HTML to only load partially. LogCat then shows:
Unknown chromium error: -6
If I keep the files as they are, the HTML loads correctly, but obviously with broken images. I've also tried to change the URLs to file:///data/data/<id>/files/ [...], which also causes the HTML to not load completely. I have really no idea what is causing this problem. The app already has the WRITE_EXTERNAL_STORAGE permission.
Does anyone have an idea how to fix this? Thank you!
Turns out this error was caused by having images that are larger than 1500px in width. After scaling them down, the error disappears. Must be a problem with the Android webview, I guess.

Categories

Resources