Hi, My app needs to download picture from internet time to time and store them to show when it runs according to the selection. how can i download the pictures and what is the way to store them in my application folder or etc. i m trying to use file output stream on application local folders such as assets and drawable but so far no luck in finding the correct path for it.
A:
To download the images I suggest you use the Apache HttpClient libraries, which are built into the Android SDK. Here's a tutorial that can get you started quickly with HttpClient: http://hc.apache.org/httpcomponents-client-4.0.1/tutorial/html/fundamentals.html
To store the images, the following code will get you your app's data directory. The data directory is located on the device filesystem at /data/data/your.package.name/files/
.
Context ctx = activity.getApplicationContext();
String dataDir = ctx.getApplicationInfo().dataDir;
If you're interested in storing the images permanently in your user's Gallery, there are APIs for doing that in the MediaStore
class.
Neil Traft
2010-08-11 07:22:44
Thanks, But the thing is i need to download the images to a application local folder and show them in my web view. i can download them to the applications data directory using above way but how can i give the reference to my web views loadDataWithBaseURL() method to load the images from that location. how can i do it?
2010-08-13 06:02:41
I don't quite understand what you need to do. You need to show the images inline with text and other HTML? If you have a document that references the image as a local file then I guess you should probably be able to use "file:///data/data/your.package.name/files/" as your base URL? But if you only need to load images then why not just use `ImageView`.
Neil Traft
2010-08-15 15:39:16