Reputation: 1259
I am a beginner in android programming. Here is a code to take a image and save it in a folder in sdcard. The image is saved in gallery but it is not saved in the location where i want to. Please help...
public class CameraActivity extends Activity {
/** Called when the activity is first created. */
Button button1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1=(Button)findViewById(R.id.button1);
}
public void send(View v)
{
Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(
Environment.getExternalStorageDirectory(),
"MyImages");
imagesFolder.mkdirs(); //
File image = new File(imagesFolder, "image_001.jpg");
Uri uriSavedImage = Uri.fromFile(image);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(imageIntent,0);
}
}
Upvotes: 1
Views: 223
Reputation: 1259
Finally I got the solution, the modified code is:
File image = new File("/sdcard/picture.jpg");
Uri uriSavedImage = Uri.fromFile(image);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
Upvotes: 2
Reputation: 2293
You should append a /
to your MyImages string. eg,
new File(Environment.getExternalStorageDirectory() + "/MyImages/");
That should create a reference to a directory, not a file as it currently is.
Upvotes: 0