Ronn Ronn -4 years ago 428
Android Question

Getting Failed to find configured root that contains /storage/emulated/0/Pictures/NoteTaking/IMG_20170226_231007.jpg while trying to take a photo

I am trying to make an app that takes a photo and displays it using emulator instead of a device. I followed the steps from this android doc:

Part 1) Here is my code where it gets stucks :

file = FileProvider.getUriForFile(this, "", createFileDir());

This part is in the Mainxml

public void takePicture(View view){
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = FileProvider.getUriForFile(this, "", createFileDir());
String s = file.getPath();
Log.v("File Path","File path is"+s);
private static File createFileDir(){
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "NoteTaking");

if (!mediaStorageDir.exists()){
if (!mediaStorageDir.mkdirs()){
Log.d("NoteTaking", "failed to create directory");
return null;

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return new File(mediaStorageDir.getPath() + File.separator +
"IMG_"+ timeStamp + ".jpg");

Here is my app manifest file's provider section

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

android:resource="@xml/provider_paths" />

and provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="">
<external-path name="external_files" path="Android/data/"/>

Part 2) If i keep provider_paths as this

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="">
<external-path name="external_files" path="."/>

I am able to open camera app, take photo and view it on the same page, but, here is the catch, I am storing the path into database and trying to retrieve all the images on a page. Here is when it gives an error:

Unable to decode stream: /external_files/Pictures/NoteTaking/IMG_20170226_230608.jpg (No such file or directory)

Answer Source

Try this surely it will work:

Uri mImageCaptureUri;
private void operCamera() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
            "tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));

    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);

    intent.putExtra("return-data", true);

    startActivityForResult(intent, 1);

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1 && mImageCaptureUri != null && resultCode != 0) {
        if (mImageCaptureUri != null) {
            String path1 = mImageCaptureUri.getPath();
            if (path1 != null) {
                File file1 = new File(path1);
                Uri capturedUri = Uri.fromFile(file1);//here you get the URI
                //you can easily get the path from URI if you need
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download