KijeviGombooc
KijeviGombooc

Reputation: 342

Unable to get provider androidx.core.content.FileProvider: java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data?

I've looked at many posts liks this, but still don't know what the problem is. I Tried changing path and name in file_paths.xml.

file_paths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="pirosfogo_images"
path="storage/emulated/0/pictures/"/>
</paths>

AndroidManifest.xml:

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

java:

void takePhoto(){
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
    {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 110);
    }
    else
    {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (intent.resolveActivity(getPackageManager()) != null)
        {
            File photoFile = createPhotoFile();
            if(photoFile != null){
                pathToFile = photoFile.getAbsolutePath();
                Uri photoURI = FileProvider.getUriForFile(ProfileEdit.this, "adada", photoFile);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(intent, REQUEST_CAMERA);
            }
        }
    }
}
private File createPhotoFile() {
    String name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File image = null;
    try{
        image = File.createTempFile(name, ".jpg", storageDir);
    } catch(Exception e){}
    return image;
}

Why do I get the error?

Upvotes: 3

Views: 11576

Answers (2)

SHUBHAM SONI
SHUBHAM SONI

Reputation: 111

In my case I have forgot Camera Permission so that i have added permission in AndroidManifest.xml:

   <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.CAMERA" />
<application
    android:allowBackup="true"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.MyAppName"
    tools:targetApi="31">
    <activity
        android:name=".MainActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.example.myappname.fileProvider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_path"
            />
    </provider>
</application>

Upvotes: 0

Edric
Edric

Reputation: 26740

This is because you've specified the <meta-data> tag in the wrong parent (<application> tag). It should be specified within the <provider> tag. (The two code snippets below show the difference:)

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

VS

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

Upvotes: 6

Related Questions