2

I would like some help with saving pictures taken from my camera to a specific folder on the SD card. My camera opens up, takes the photos, and saves them; but it saves them to the standard folder. The code I have so for is:

public class Camera extends Activity {
public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
String Path;
private Uri fileUri;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle extras=getIntent().getExtras();
    Path= extras.getString("Path");
    Log.d("camear","path: "+Path);
    //File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp");

    Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
        this.startActivity(intent);
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    //mediaFile = new File(mediaStorageDir.getPath() + File.separator +"IMG_"+ timeStamp + ".jpg");

    //fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
    Uri outputFileUri= Uri.fromFile(new File(Path+"/camera/"+timeStamp+".jpg"));// create a file to save the image
    intent.putExtra("output", outputFileUri); // set the image file name

    // start the image capture Intent
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

The path is coming from another activity on the application, and it passes its values fine. In the previous activity, it creates the folders that I want to save the pictures into.

I have looked at the following answer, and tried to implement some of the suggestions: How to save images from Camera in Android to specific folder?. One thing I didnt try, was in the last suggestion on the OnActivityResult. Is that the key or is there somthing else I am missing? This page here mentions the ContentResolver The Camera Intent is simply not working, one thing is that both pages look like they want to do the same, but go about it in different ways.

Community
  • 1
  • 1
Paul Robert Carlson
  • 169
  • 1
  • 2
  • 14
  • 1
    Paul, add this `intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);` – ρяσѕρєя K Mar 25 '12 at 06:12
  • are you suggesting adding it to the file or replacing the other intent.putExtra that I already have? When I try adding and or replacing with it, Still does the same. Using my debugger, I see that outputFileUri is pointing to: file:///mnt/sdcard/BucketMonkey/32rm215/camera. Is it just standard for it to add the last file of camera to the path? I do not have a mkdir for the path including camera, would that be causing my issue? – Paul Robert Carlson Mar 25 '12 at 20:11
  • I cant edit my previous post, but ignore my comment about the camera be attached to the end, that was my own fault. But even when the path is to a legitimate folder, it still saves in the main camera folder. – Paul Robert Carlson Mar 25 '12 at 20:26
  • Could you paste your onActivityResult(int requestCode, int resultCode, Intent data){ – Manu Mar 01 '17 at 12:19

1 Answers1

1

I figured out what I was doing wrong. If you look at the code, I made two mistakes. The first mistake was with my path. I got the correct path from the previous activity, however I did not create a folder path here. This is the code that worked for me:

File Folder=new File(Path);
File picFile= new File(Folder.getPath()+"/"+timeStamp+".jpg");

The first line checks for the folder, the second line creates the file using the path to the folder. I didn't have either part. Without it finding the path, it was just saving were it wanted to.

Another issue that I had was with my Intent call, I used the: MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA. This without any @Overrides apparently acts like the actual camera saving in its folder. I changed this to:
MediaStore.ACTION_IMAGE_CAPTURE, which allows me a little more control.

Another issue that I Was having and figured out, was with the ACTION_IMAGE_CAPTURE, it would take and the close out. But if you implement onActivityResult using the result code returned from the camera application, you can either re-call the camera and make it run again, or you can close it out and go back to another activity. It was not part of the original question, but was an issue I was having.

Paul Robert Carlson
  • 169
  • 1
  • 2
  • 14