1

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>
And_dev
  • 13
  • 1
  • 4

1 Answers1

2

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.

Community
  • 1
  • 1
MH.
  • 45,303
  • 10
  • 103
  • 116
  • Thanks for the solution. My emulator is 2.3.1 and phone has 2.1 version. Using assets folder, I can display the image in 2.1 as well – And_dev Dec 04 '11 at 16:56