Bigflow
Bigflow

Reputation: 3666

Give name to image when used intent camera

In my app, I open the camera and want to save that file with a specific name. I use this code:

public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("new-photo-name.jpg")) );
        startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

}
protected void onActivityResult1(int requestCode, int resultCode, Intent data) {
                    if (requestCode == CAMERA_PIC_REQUEST) {
                          Bitmap image = (Bitmap) data.getExtras().get("data");  
                    }   
}

It does open the camera, I can take and save the photo, but it does not give the good name. Everytime when I save the picture, he gives the picture an other name, 1 name example is: "13333675392558.jpg". I don't understand how he comes with that kind of numbers.

Why does my code does not apply the name: "new-photo-name.jpg" ?

And/Or what do I wrong then?

Thanks already, Bigflow

Upvotes: 1

Views: 1203

Answers (2)

Bigflow
Bigflow

Reputation: 3666

I got it working, but don't know the exact same problem yet, but this code worked for me:

private Uri outputFileUri;
    public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File file = new File(Environment.getExternalStorageDirectory(), "/DCIM/Camera/new-photo-name.jpg");

        outputFileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, TAKE_PICTURE);
    }

onLongPress has something to do with gesture (touch) actions, you could also use a button here.

public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == TAKE_PICTURE){
            System.out.println("string of file name = "+outputFileUri.toString());
      }
}

Really small code, but works like a charm

Upvotes: 0

pouzzler
pouzzler

Reputation: 1834

intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);

is the line that sets the filename. It's this line you must change.

Upvotes: 1

Related Questions