Wednesday, 30 November 2011
Monday, 14 November 2011
Checking Connection Timed out in android
Plz follow this link http://stackoverflow.com/questions/693997/how-to-set-httpresponse-timeout-for-android-in-java
Plz follow this link http://stackoverflow.com/questions/693997/how-to-set-httpresponse-timeout-for-android-in-java
Tuesday, 8 November 2011
WebView with zoom controls, image from SDCARD
The Problem:
When I'm trying to load an image (tried both gif and png) from my assets directory, into a webview.
In my assets folder, I have an image called myImage.gif
Here's my wrong code:
All that happens when I try it, is that I get a blank screen with a
empty 42px/42px box.
In logcat, I see the message:
03-30 00:21:14.398: DEBUG/WebCore(214): Console: Not allowed to load
local resource: file:///android_assets/myImage .gif line: 0 source:
The Solution:
Even though, I'm going to load the image file from the filesystem (SDCARD or Phone Storage), instead of Assets folder, I've found a solution for this, and you don't even have to care about ContentProviders... (Which is also a good solution, but this is much easier & quicker in this case.)
The key is WebView's loadDataWithBaseURL method, but let's see an example:
When I'm trying to load an image (tried both gif and png) from my assets directory, into a webview.
In my assets folder, I have an image called myImage.gif
Here's my wrong code:
- WebView data = (WebView) findViewById(R.id.data)
- data.loadData("<IMG HEIGHT=\"42px\" WIDTH=\"42px\" SRC=\"file:///android_assets/myImage
.gif\" />", "text/html", "UTF-8");
All that happens when I try it, is that I get a blank screen with a
empty 42px/42px box.
In logcat, I see the message:
03-30 00:21:14.398: DEBUG/WebCore(214): Console: Not allowed to load
local resource: file:///android_assets/myImage
The Solution:
Even though, I'm going to load the image file from the filesystem (SDCARD or Phone Storage), instead of Assets folder, I've found a solution for this, and you don't even have to care about ContentProviders... (Which is also a good solution, but this is much easier & quicker in this case.)
The key is WebView's loadDataWithBaseURL method, but let's see an example:
- /* Using WebView to display the full-screen image */
- WebView full = (WebView)findViewById(R.id.webview);
- /* Set up the Zoom controls */
- FrameLayout mContentView = (FrameLayout) getWindow().
- getDecorView().findViewById(android.R.id.content);
- mContentView.addView(zoom, ZOOM_PARAMS);
- /* Create a new Html that contains the full-screen image */
- html = ("<html><center&g
t;<img src=\""+fileName+"\"></html>" ); - /* Finally, display the content using WebView */
- full.loadDataWithBaseURL("file:///sdcard/data/data
/com.youproject.example/" , - html,
- "text/html",
- "utf-8",
- "");
Subscribe to:
Posts (Atom)