Matthew
Matthew

Reputation: 3956

Obtaining image from camera intent on Android

I am following the Google tutorial on launching a new intent to take and deliver a photo. https://developer.android.com/training/camera/photobasics. I am unable to get past a certain spot because I get this exception: Failed to find configured root that contains /storage/emulated/0/Android/data/com.example.matthew.doodlewits/files/Pictures/JPEG_20190108_220143_4398098916939163453.jpg

The exception happens at

Uri uri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", image);

In the below method:

private void takePictureSetup()
    {
        try
        {
            Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);

            String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String imageFileName = "JPEG_" + timestamp + "_";
            File storageDirectory = this.getExternalFilesDir(Environment.DIRECTORY_PICTURES);

            File image = File.createTempFile(imageFileName, ".jpg", storageDirectory);

            currentPathToPictureTaken = image.getAbsolutePath();

            Uri uri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", image);

            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            startActivityForResult(intent, this.RESULT_CAMERA_PHOTO);

        }
        catch(Exception e)
        {
            Log.d("**EXCEPTION**", e.getMessage());
        }

    }

This is the XML file that I have created:

enter image description here

And here is the xml layout code of that file:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="my_images" path="Android/data/com.example.package.name/files/Pictures" />
</paths>

And finally in my manifest file:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">



        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.example.android.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>


    </application>

Upvotes: 2

Views: 1073

Answers (1)

Ye Min Htut
Ye Min Htut

Reputation: 2904

The problem is at your provider path

Your current provider path is

Android/data/com.example.package.name/...

It should be

Android/data/com.example.matthew.doodlewits/...

Hope it helps

Upvotes: 4

Related Questions