I have stored some images in res folder of my app. But the user can download this image to their sdcard using the download option. How can I copy the image in res folder to sdcard. Can anyone help me.
Asked
Active
Viewed 1,561 times
2
-
2either use screen capture code or put the image in assest folder – ingsaurabh Oct 31 '11 at 12:08
-
+1, ya, as per ingsaurabh suggested put image in asset folder or load image in activity then capture screen but it is ugliest way, just put image in asset and copy it to sdcard. – user370305 Oct 31 '11 at 12:12
2 Answers
3
You can do something like this,
if (isSdPresent()) { // to check is sdcard mounted
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
Bitmap bbicon = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
String extStorageDirectory = Environment.getExternalStorageDirectory()+ File.separator + "FolderName";
File wallpaperDirectory = new File(extStorageDirectory);
wallpaperDirectory.mkdirs();
OutputStream outStream = null;
File file = new File(wallpaperDirectory,"icon.png");
//to get resource name getResources().getResourceEntryName(R.drawable.icon);
try {
outStream = new FileOutputStream(file);
bbicon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
}
to check SDCard
public boolean isSdPresent() {
return android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
}

MKJParekh
- 34,073
- 11
- 87
- 98
1
Maybe this could help you getting a stream from your image and posting it to the user to download...