0

Hello i want to capture image from camera and store into specific folder. For ex. I have folder with name "MyImages" and i want to store captured image with name abc.png into this folder , So how can i set path of FileProvider for following code snippet.

<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_images" path="???"/>
...

Following is my code where i am create my image file.

public File getAlbumDir() {
    File storageDir = null;

    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {

        storageDir = new File(Environment.getExternalStorageDirectory(),
                "MyImages");

        if (storageDir != null) {
            if (!storageDir.mkdirs()) {
                if (!storageDir.exists()) {
                    Log.d("CameraSample", "failed to create directory");
                    return null;
                }
            }
        }

    } else {
        Log.v(context.getString(R.string.app_name), "External storage is not mounted " +
                "READ/WRITE.");
    }

    return storageDir;
}

public File createImageFile() {
    // Create an image file name
    String imageFileName = "abc.jpg";
    File albumF = getAlbumDir();
    File imageF = new File(albumF, imageFileName);
    return imageF;
}
Floern
  • 33,559
  • 24
  • 104
  • 119
Akash Ratanpara
  • 240
  • 1
  • 2
  • 14
  • "I have folder with name "MyImages"" -- please explain, **in detail**, where this folder exists. – CommonsWare May 15 '17 at 13:06
  • This Folder exists in SD card. If you know how to set path then please help me. – Akash Ratanpara May 15 '17 at 13:06
  • Try this link http://stackoverflow.com/questions/20058793/android-how-to-save-the-camera-result-to-a-private-file – Ankita May 15 '17 at 13:12
  • "This Folder exists in SD card" -- please explain, **in detail**, where this folder exists. For example, you could edit your question and show the code where you create this folder. – CommonsWare May 15 '17 at 13:12

1 Answers1

3

You have MyImages/ off of Environment.getExternalStorageDirectory().

First, that is not a good place to be putting files. That is akin to creating a directory in the root of C:\ on Windows.

That being said, in your FileProvider XML configuration, you need:

<external-path name="my_images" path="MyImages"/>
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491