Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android Not allowed to load local resource:file:///android_asset

I'm trying to load an html page from a server the page contains a script that links to android sdcard .js file.

Java:

String url ="http://192.168.84.86:8080/test/maw/js_load_test.html";
this.loadUrl(url);

js_load_test.html:

<script src="file:///sdcard/test.js"></script>

I've also tried :

<script src="file:///android_asset/www/js/test.js"></script>

test.js file exists and js file path is correct. But in logcat: file:///sdcard/test.js:

03-18 13:01:12.467: E/Web Console(26189): Not allowed to load local resource: file:///sdcard/test.js at :0

file:///android_asset/www/js/test.js:

03-18 13:01:53.467: E/Web Console(26189): Not allowed to load local resource: file:///android_asset/www/js/test.js at :0

like image 633
explorer Avatar asked Mar 18 '12 13:03

explorer


2 Answers

This may help

https://groups.google.com/group/android-developers/browse_thread/thread/e20e87d2faf9ff41?pli=1#

webview.loadDataWithBaseURL( "file:///android_asset/", html, "text/html", 
"utf-8", null ); 
like image 57
Sindre Avatar answered Sep 21 '22 07:09

Sindre


If you getting "Not allowed to load local resource: file:///android_asset/index.html" error most probably your problem is putting assets folder in wrong location.

For gradle project store your assets folder under src/main/ directory by the java and res folders. Like this:

project-folder -|project_name
--|build
--|src
---|assets
---|gen
---|java
---|res

For maven project store yout assets under res/ directory

like image 38
Defuera Avatar answered Sep 22 '22 07:09

Defuera