webview can't access local files?

5 replies [Last post]
buy ugg boots
User offline. Last seen 2 years 25 weeks ago. Offline
Joined: 11/19/2009

Hello everyone!
I tried to use webview to load local html file
(for convenience, I modified sample project ApiDemos ./development/samples/ApiDemos/src/com/example/android/apis/view/WebView1.java)

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.webview_1);
final String mimeType = "text/html";
final String encoding = "utf-8";
WebView wv;
try {
InputStream is = getAssets().open("HelloWorld.html"
int size = is.available();
// Read the entire asset into a local byte buffer.
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
// Convert the buffer into a string.
String strContent = new String(buffer);

wv = (WebView) findViewById(R.id.wv1);
wv.loadData(strContent, mimeType, encoding);
} catch (IOException e) {
// Should never happen!
throw new RuntimeException(e);
}
}

HelloWorld.html & HelloWorld.css is saved in folder : ./ApiDemos/assets

@import "HelloWorld.css";


Hello, World!

After startup the emulator, I pushed default.png in to folder /data/data/com.example.android.apis/,

But when I run ApiDemos->View->WebView, the image does not show up, and here is the information in log:
D/WebCore ( 216): Console: Not allowed to load local resource: file:///data/data/com.example.android.apis/default.png line: 0 source:

So, what's the proplem?

davidmurree
User offline. Last seen 4 days 22 hours ago. Offline
Joined: 09/27/2010
ARY Musik

you solve this issue very well.The following article actually established my very own little brown eyes towards the several merchants which usually organizations currently have by means of internet marketing.i like to read informative blogs and this blog is also so good and helpful.thanks for taking time to discus this topic..
ARY Musik

1xuntong
User offline. Last seen 20 weeks 5 hours ago. Offline
Joined: 12/25/2011
miu miu

Golden cherubim prada tote bag 2012 the border of yellow, green hand wan xia ROM peony mist the yarn

Ronnyz
User offline. Last seen 1 year 1 week ago. Offline
Joined: 05/06/2011
Yeah thanks for resolving

Yeah thanks for resolving this issue. now the problem is solved.

Regards
Ron H.

pandorauk
User offline. Last seen 1 year 22 weeks ago. Offline
Joined: 12/07/2010
it is sometimes world of hard

it is sometimes world of hard to Pandora in a world of adults Pandora Bracelets

buy ugg boots
User offline. Last seen 2 years 25 weeks ago. Offline
Joined: 11/19/2009
I have solved this problem ^_^.

I put all the HTML related files under folder "/$path of your application$/assets/"
and then, I replace function "loadData" with "loadUrl" , and it does work!

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.webview_1);
final String mimeType = "text/html";
final String encoding = "utf-8";
WebView wv;
wv = (WebView) findViewById(R.id.wv1);
wv.loadUrl("file:///android_asset/HelloWorld.html"

}