4

I am trying to develop an app that takes photos, and later that uploads them to a database. Right now I am stucked at taking a good quality photo. As I read before, to get a better quality photo you need to save it in your directories. I am following the Google Take Photos from developers instructions, and after adding all the methods and provider and so on, I get the error :

Couldn't find meta-data for provider with authority com.example.navigationdrawerfinal. 

I've left the name of my app so everyone can see that I changed it in manifest too.

Manifest:

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.example.navigationdrawerfinal.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

file_paths.xml :

<?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.navigationdrawerfinal/files/Pictures" />
</paths>

and the code where I use it:

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.example.navigationdrawerfinal",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
            poza_neincarcata.setVisibility(View.GONE);
            poza_tick.setVisibility(View.VISIBLE);
        }
    }
}


private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );

        // Save a file: path for use with ACTION_VIEW intents
        currentPhotoPath = image.getAbsolutePath();
        return image;
    }
Costin
  • 194
  • 1
  • 2
  • 16
  • 3
    You've specified the authority in the manifest as `com.example.navigationdrawerfinal.fileprovider`, but the `FileProvider.getUriForFile()` call is using `com.example.navigationdrawerfinal`. Those don't match. – Mike M. Dec 16 '19 at 10:03
  • 1
    Yes @MikeM. That was the mistake I did not see. It is working now, thanks! – Costin Dec 16 '19 at 10:06

2 Answers2

10

As indicated by the error (emphasis is mine):

Couldn't find meta-data for provider with authority com.example.navigationdrawerfinal.

This is because you've specified the incorrect FileProvider needed for the photoURI variable you've defined - it should exactly be the same as the FileProvider you've defined in your manifest file, case-sensitive:

Uri photoURI = FileProvider.getUriForFile(this,
                    "com.example.navigationdrawerfinal.fileprovider", // Over here
                    photoFile);

By the way, it's a good idea to follow the Java guidelines by naming your classes in PascalCase format.

For e.g.:

  • FileProvider vs fileprovider
  • MainActivity vs mainActivity

etc.

Edric
  • 24,639
  • 13
  • 81
  • 91
3

in our manifest change like this

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
Ramadanrizky87
  • 218
  • 2
  • 11