T.dog T.dog - 5 months ago 14
Android Question

Set the path of a folder

I'd like to save pictures into a folder what I have created dynamically. I have a container folder which name is "Eskuvo" and inside that I can create new folders. When I open one of them I'd like to take a picture and save it inside that folder. The problem is that no matter how I give the name of the folder the app always save the picture into the "Eskuvo" folder. I copy my code:

ImagesViewF.java:

public void TakingPictures(){

File photos = new File("/sdcard/Eskuvo/"+ca.copyname+"/");
photos.mkdirs();

count++;
String file = "/sdcard/Eskuvo/"+ca.copyname+count+".jpg";
File newfile = new File(file);

try{
newfile.createNewFile();
}catch (IOException e){
e.printStackTrace();
}

Uri outputFileUri = Uri.fromFile(newfile);

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

getActivity().startActivityForResult(cameraIntent, 0);
}


I'd like to mention that
ca.copyname
is the name of the folder where I'd like to save. I hope you could help me.

Answer

This code:

"/sdcard/Eskuvo/"+ca.copyname+count+".jpg";

will create files like these:

"/sdcard/Eskuvo/filename1.jpg";
"/sdcard/Eskuvo/filename2.jpg";
"/sdcard/Eskuvo/filename2.jpg";
"/sdcard/Eskuvo/filename2.jpg";

Use this code:

count++;
String file = ca.copyname+count+".jpg";
File newfile = new File(photos, file);

To create a file in newly created folder.

Comments