i_me_mine
i_me_mine

Reputation: 1433

why is the file saving here?

When I take a photo with my app I would like to save it like this

Android/data/com.androidproject/files/Camera/photo.png

However it is currently saving here, according to my Log.v statement

file:///storage/emulated/0/Android/data/com.androidproject/files/Camera/photo.png

This is my code

private class ClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            File dir = new File(getActivity().getExternalFilesDir("Camera"),
                    "photo.png");               
            Uri outputFileUri = Uri.fromFile(dir);
            Log.v("FILE", "" + outputFileUri);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(intent, CALL_BACK);
        }

    }

So, why isn't the file saving to the desired location? How do I fix it?

Upvotes: 0

Views: 862

Answers (1)

Matt Clark
Matt Clark

Reputation: 28579

use getFilesDir() instead of getExternalFilesDir() to save them to the internal memory.

File f = new File(getFilesDir() + File.separator + "Camera" + File.separator + "photo.png");
f.mkdirs();

This will setup your new file, and make sure the path to it exists.

Upvotes: 1

Related Questions