Reputation: 13
I have went through all the posts on displaying local images on android phone. I can see the local image on emulator but on phone - "Webpage not available". However I can load other webpages on phone with webView.loadUrl("http://www.google.com/");
I have set internet permissions
<uses-permission android:name="android.permission.INTERNET"/>
The image is in raw folder and using display.html file to read it
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.loadUrl("file:///android_res/raw/display.html");
// display.html in raw folder
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<img src="file:///android_res/raw/image.jpg" width="50px" alt="Hello">
</body>
</html>
Upvotes: 1
Views: 1544
Reputation: 45493
Are you by any chance running the code on a phone with API Level < 8 (Android 2.1 and lower) and testing it on an emulator running a more recent version?
file:///android_res/...
only works for 2.2+.
Alternatively you can try putting the image in the assets folder and reference it by file:///android_asset/...
, which apparently is also supported on devices running older versions. Unfortunately you will lose the ability to automatically load up resources appropriate to the device's screen size and density.
Upvotes: 2