Xamarin Forms app for IOS and Android using MediaPlugin.
Only on some android instances this is not working and throwing the exception below.
The Argument Exeception thrown is:
"Unable to get file location. This most likely means that the file provider information is not set in your Android Manifest file. Please check documentation on how to set this up in your project."
Since AppCenter has no way of reporting handled exceptions properly, i have only an eventtype and no stacktrace, device info or anything, but my guess is it happens after calling await CrossMedia.Current.TakephotoAsync(...)
The error suggests i have not setup the fileproviders properly, but the fileprovider info is exactly setup as provided in the readme files. It is working on all my Android test devices and emulators.
My file_paths.xml file:
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-files-path name="my_images" path="Pictures" /> <external-files-path name="my_movies" path="Movies" /> </paths>
And this is set in the AndroidManifest.xml:
<manifest...> <application...> <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.myappname.nl.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data> </provider> </application> </manifest>
What can be wrong on the problematic instances?
When i use below file_paths.xml file (exactly as mentioned in the mediaPlugin README!)
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-files-path name="my_images" path="Pictures" /> <external-files-path name="my_movies" path="Movies" /> </paths>
It works only when the default location for memory in Android settings is set to internal memory. When set to SD-Card IT DOES NOT WORK!
When i change file_paths.xml file to this:
<?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.plugin.mediatest/files/Pictures" /> </paths>
It works for BOTH internal memory and SD-Card.
Above modification was the solution for me, but i'm really curious why the suggested settings from MediaPlugin (https://github.com/jamesmontemagno/MediaPlugin/blob/master/README.md#android-file-provider-setup) do not work.
Maybe update the readme?
Answers
Have you added this
https://us.v-cdn.net/5019960/uploads/editor/c7/snwmvbciwsv9.png
@charwaka, same issue after adding the line also
@Kevelop
Did you find the solution?
Try this Sample And tell me its working or not
https://github.com/jamesmontemagno/MediaPlugin/tree/master/samples
> @Kevelop said:
> @Charwaka @nrb1238 I have that line as well. It is not the solution unfortunately
>
>
>
>
>
> Try this Sample And tell me its working or not
>
> https://github.com/jamesmontemagno/MediaPlugin/tree/master/samples
I can't reproduce the error locally. It's happening in the field. So I was hoping someone figured out what could cause it, because I can't yet
I'm having the same problem; I've been able to run the sample with no trouble, but copying the code from the Android Manifest, file paths, Main Activity and the exact same code in the button, I'm still having this error. The only other difference I can see is that I'm using Android views instead of x-forms. Could this be the reason I'm having this problem?
@Kevelop, @Charwaka my issue is fixed. for me it is because of case sensitive. package name and android:authorities should be same(with all lowercase) then it is working fine
If there was a problem with that, shouldn't it fail always? The problem is that i have hundreds of installs that work, but just a couple of tens of installs that have this problem... mixed Android versions, mixed device types etc.
My error was a human mistake as well. There where two tags in my Android Manifest, and the provider was in the second one; that's why it was never recognized as added. I found about this error by checking the generated Android Manifest in obj/Debug/android; maybe this could give a hint to anyone else having this problem.
@Charwaka I managed to reproduce the error. Even the sample from MediaPlugin itself crashes!
To reproduce you have to switch the default from Internal memory to SD card from within the Android settings.
After that, it crashes before you can even take a picture!
(@JamesMontemagno : Do you have any idea how to resolve this? )
See stacktrace:
https://stackoverflow.com/questions/42516126/fileprovider-illegalargumentexception-failed-to-find-configured-root
Not sure what you're trying to say here. That stackoverflow post is about someone who has not setup his file_paths.xml correctly according to the mediaPlugin readme. I have. And also, the mediaplugin sample, which is setup correctly, is crashing. If i however remove the path attribute from the external-file-paths tag, i get the exception:
So, what is really the problem here, i don't understand. If both the manifest and the file_paths.xml are setup as mentioned in the MediaPlugin readme, it should work, right?
yes ,it should work.have you tested in other Devices ??
When i use below file_paths.xml file (exactly as mentioned in the mediaPlugin README!)
It works only when the default location for memory in Android settings is set to internal memory. When set to SD-Card IT DOES NOT WORK!
When i change file_paths.xml file to this:
It works for BOTH internal memory and SD-Card.
Above modification was the solution for me, but i'm really curious why the suggested settings from MediaPlugin (https://github.com/jamesmontemagno/MediaPlugin/blob/master/README.md#android-file-provider-setup) do not work.
Maybe update the readme?
@Kevelop how did you manage the
<external-path name="my_images" path="Android/data/com.plugin.mediatest/files/Pictures" />
Is this path general from the Media Plugin or it's depend in our own path?
I figured out the problem, it turn out the "YOUR_APP_PACKAGE_NAME.fileprovider" was the problem. I shouldn't set this to random text instead I should based on Package name on Android Properties and now its working fine even without changing file_paths.xml or any file which are described on Plugin doc.
@Kevelop Thanks. It's working again.
As per your suggestion, i have updated the android attributes. Now its working perfectly for me. Thank you for sharing your input.
Just to explain the accepted answer,
<external-files-path name="my_images" path="Pictures" /> <--------- wrong tag
<external-path name="my_images" path="Pictures" /> <--------- correct Tag
The sample is working fine, but with my app it took hours to figure out and trying different solutions.
What did it for me is changing path to "." in the xml file
<?xml version="1.0" encoding="utf-8" ?>
<paths>
<external-files-path name="my_images" path="." />
</paths>
from here found the answer
stackoverflow.com/a/48008968/10327213
Hi,
Your issue is that the your AndroidManifest.xml file references 'android:authorities="com.myappname.nl.fileprovider"', but then your app package ID is actually "com.plugin.mediatest".
If you make them the same, then the first way you had the files_path file would work. I just noticed this on mine and fixed it.
I done it. It's very easy a little bit difference in it
this one
var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
Any update on this? I am having the same problem and all the potential solutions in this thread are not working.
I solved it. For me the problem was that:
was not nested in the
<manifest>
tag instead of under the<application>
tag where it belongsMake sure the name of the project is in agreement with the manifesto I touched the name of the project and ended up falling on this problem.
Make sure the name of the project is in agreement with the manifesto I touched the name of the project and ended up falling on this problem.
manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.7.2" package="ProjectName" android:versionCode="33"
provider android:name="android.support.v4.content.FileProvider" android:authorities="br.com.eaglelog.eaglelog.fileprovider" android:exported="false" android:grantUriPermissions="true"
meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /meta-data
falling on this problem.
>
Also, make sure the provider tag is nested inside application. i was banging my head until i realized i had put it outside.
an example, in androidmanifest.xml:
This works for me
<?xml version="1.0" encoding="utf-8"?>
> @developmedev said:
You can make it simple if you try the below code.
<?xml version="1.0" encoding="utf-8"?>