I'm making a gallery in which I load (on run time) images from asset folder. Now I want to save image to SD card on the click event.
For example: When the app starts, the user see images, they can scroll through images and view them (this part is done). The problem is pictures are loading dynamically in my own gallery view. I have not hard coded them.
I want to save it to the SD card. But I don't have the hard coded path of images. There can be any number of images.
private void CopyAssets() {
AssetManager assetManager = getAssets();
InputStream in=null;
String[] files = null;
try {
files = assetManager.list("image");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
for(String filename : files) {
try {
in = assetManager.open(filename);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
String dirName = Environment.getExternalStorageDirectory().toString();
File newFile = new File(dirName);
newFile.mkdirs();
OutputStream out = new FileOutputStream(newFile);
System.out.println("in tryyyy");
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(Exception e) {
Log.e("tag", e.getMessage());
}
I tried above method, I don't want to copy all the image to the SD card. But only that one which the user chooses from the gallery that too dynamically. As there will be a number of images. Hard coding each image path will be tough.
Is there any way in Android, by which I can get the current image path or URI in a string? What is View v = this.getCurrentFocus();? What does it return?