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 folde开发者_JS百科rs such as assets and drawable but so far no luck in finding the correct path for it.
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.
精彩评论