I know this is an oldie, but I do not seem to find a way to manage it...
I've to capture a Camera image for later IO processing, transferring it to a network share, but I fail lot before this...
after some reading here, I found the way to actually do it on KitKat checking the running SDK, and it works..
but, now I'm testing it on a Nougat device as well..
for Nougat I've read a provider should be used, and I'm trying to...
the captured image MUST be stored in a particular folder which is
"/storage/emulated/0/InsulinPower/amSignTool/Data"
for later IO processing... so I think something similar to
must be used, currently with no look..
I had a look at provider definition for all "area", but can not get the answer I need and more I get exceptions.. as defining the retrival URI I get
java.lang.reflect.InvocationTargetException
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/InsulinPower/amSignTool/Data/XCAMX-201805171828082115829615.jpg
in the file_paths I tried quiet everything, as you can see... but it only works if I do refer external-path and NOT external-path-files, which indeed seems to be the one I need..external-path
the code is trivial....
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
File pictureFile = null;
try {
pictureFile = GENERIC.amPictureFile(this);
} catch (IOException ex) {
// Error occurred while creating the File
Toast.makeText(this, "Create file failed!", Toast.LENGTH_SHORT).show();
}
if (pictureFile != null) {
//https://stackoverflow.com/questions/40087944/content-uri-crashes-camera-on-android-kitkat
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT){
this.imageToUploadUri = Uri.fromFile(pictureFile);
} else {
this.imageToUploadUri = FileProvider.getUriForFile(this,"com.insulinpower.android.fileprovider", pictureFile); // <-- THIS statement crashes with the indicated exception
}
//\ https://stackoverflow.com/questions/40087944/content-uri-crashes-camera-on-android-kitkat
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
}
// file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Share folder under public external storage folder.The base folder is Environment.getExternalStorageDirectory()-->
<!--external-path name="my_data" path="InsulinPower/amSignTool/Data/" /> -->
<external-files-path name="my_data" path="/InsulinPower/amSignTool/Data/" />
<!-- external-files-path name="my_data" path="InsulinPower/amSignTool/Data/" / -->
<!-- external-files-path name="my_data" path="/" /-->
</paths>
// manifest
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.insulinpower.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>
File storageDir = new File(Environment.getExternalStorageDirectory(),"");
returns "/storage/emulated/0" // valid, adding the /InsulinPower/amSignTool/Data suffix to go to the correct folder...
File file = this.getExternalFilesDir(null);
returns "/storage/emulated/0/Android/data/com.insulinpower.amsigntool/files" // not valid for me
any hint would be really appreciated to understand my errors, and please excuse my poor english..
TIA
Andrea