I'm having issues with File Provider. I'm trying to get the Uri of an image I take with my phone camera. But whenever I try taking a photo, it's giving me the following error:
FATAL EXCEPTION: main Process: com.example.android.inventory, PID: 30523
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.android.inventory/cache/IMG_20170718_213454_2102974580.jpg
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:679)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:378)
at com.example.android.inventory.EditorActivity$5.onClick(EditorActivity.java:239)
onClickListener
//press button to take a photo
final Button addImage = (Button) findViewById(R.id.click);
addImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {
File f = createImageFile();
Log.d(LOG_TAG, "File: " + f.getAbsolutePath());
mImageUri = FileProvider.getUriForFile(
EditorActivity.this, FILE_PROVIDER_AUTHORITY, f);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.example.android.inventory.CatalogActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.example.android.inventory.EditorActivity"
android:theme="@style/EditorTheme"
android:parentActivityName="com.example.android.inventory.CatalogActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.inventory.CatalogActivity" />
</activity>
<provider
android:name="com.example.android.inventory.data.InventoryProvider"
android:authorities="com.example.android.inventory"
android:exported="false" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.myfileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
</application>
<uses-feature android:name="android.hardware.camera"
android:required="true" />
File provider Path
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="share" path="/" />
</paths>
Any help would be appreciated. Thank you.