When I try to capture image using Camera I am getting an error,
FATAL EXCEPTION: main
Process: com.test.driver, PID: 10512
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.test.driver/files/Pictures/JPEG_20180225_110337_390840290.jpg
android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:719)
android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:404)
Here is the code I am using,
Manifest.xml
<provider
android:name="android.support.v4.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>
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.test.driver/files/Pictures" />
</paths>
Also Here is the Java code to capture Image,
private void chooseImageFromCamera() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
}
if (photoFile != null) {
Globals.imageUri = android.support.v4.content.FileProvider.getUriForFile(activity, activity.getPackageName()+".provider", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Globals.imageUri);
activity.startActivityForResult(takePictureIntent, cameraRequestCode);
}
}
}
private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
Globals.imagePath = image.getAbsolutePath();
return image;
}
I also tried by changing this
Globals.imageUri = android.support.v4.content.FileProvider.getUriForFile(activity, activity.getPackageName()+".provider", photoFile);
to
Globals.imageUri = android.support.v4.content.FileProvider.getUriForFile(activity, "com.test.driver.provider", photoFile);
but it is also not working for me.
Also on the manifest file I tried by changing
android:authorities="${applicationId}.provider"
to
android:authorities="com.test.driver.provider"
it is also not working for me.