views:

382

answers:

2

I am having a problem capturing an image and storing it from the native camera app. Here is a sample of some of my code.

_path = Environment.getExternalStorageDirectory() + "make_machine_example.jpg";
File file = new File( _path );
Uri outputFileUri = Uri.fromFile( file );

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );

startActivityForResult( intent, 0 );

After the picture has been taken and I'm returned back to my original Activity, When I navigate to my sd card via Android DDMS File Explorer the picture is not there. Anyone know why this is not being saved?

+3  A: 

Have you checked what the output of Environment.getExternalStorageDirectory() is, because if it does not contain a trailing file seperator (/) then your image will end up in a directory that does not reside on the SDcard such as:

 /mnt/sdcardmake_machine_example.jpg

When what you really want is:

 /mnt/sdcard/make_machine_example.jpg

Try this code instead:

 _path = Environment.getExternalStorageDirectory() + File.separator +  "make_machine_example.jpg";
stealthcopter
yes, I can confirm that you will need to add the file separator
Mathias Lin
+1  A: 

1 . Just use

new File(Environment.getExternalStorageDirectory(),  "make_machine_example.jpg");

and don't bother about separators.

2 . Faced the same problem before. SenseUI phones have a custom camera application that doesn't create file. What device are you using? It may already be fixed in latest devices but it may also still be an issue. So here's a complete sample how to overcome it http://stackoverflow.com/questions/2696298/problems-saving-a-photo-to-a-file/2741666#2741666.

Fedor