Hey James,
I'm running into issues with the TakePhotoAsync method.
They don't occur on iOS, nor on Android with Target SDK 23.
Note: all 'MY_PACKAGE_NAME' found below are actually containing the correct package. ;)
I've read both:
Version Number of Plugin: 2.6.2
Device Tested On: Samsung S8 (Android 7.0), iPhone 5s
Simulator Tested On: n.a.
Version of VS: Visual Studio 2017 15.3
Version of Xamarin: 2.3.4.267
Versions of other things you are using: Plugin.Permissions 1.2.1
Everything should be setup as described in the readme:
Create a view and view model where the view model holds an ICommand to handle, e.g. a button click.
Call the TakePhotoAsync in the handler.
The camera dialog will be opened and allows you to take a picture.
An exception is thrown:
Java.Lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/MY_PACKAGE_NAME/files/Pictures/IMG_20170823_130231.jpg
The 'Pictures' folder was created, both on the internal and external storage. There's just no image.
// Call this from the ICommand
private async Task TakePhoto()
{
var options = new StoreCameraMediaOption();
var media = await CrossMedia.Current.TakePhotoAsync(options);
}
What is your package name? It must be set to something like "com.company.appname"
Rest assured this works fine just try the samples.
The package name is correct and exactly in the form 'com.company.appname'.
The permissions should not be the issue. These are set (among others):
Like I said, it did work with Android API 23, but after upgrading to 25 it stopped, even though I followed the readme and add all extra settings.
If you can create a small sample that I can reproduce send it my way to test out.
I had the same problem. You need to change the file_paths.xml. It must read:
instead of:
following +1 .same problem with target sdk 24 . works fine with 23
Java.Lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/MyProject.Android/files/Pictures/PhotoDirectory/pack001Carton00102_10_2017_065131.jpg\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in 1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at Plugin.Media.MediaImplementation+<TakePhotoAsync>d__14.MoveNext () [0x000d0] in C:\\projects\\mediaplugin\\src\\Media.Plugin.Android\\MediaImplementation.cs:119 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at MyProject.ViewModel.PhotoAndCommentViewModel+
Can't reproduce
Have you read my comment? Sorry, it got corrupted somehow. It should've read:
I had the same problem. You need to change the file_paths.xml. It must read:
instead of: At least that works for me...
@obartelt can you copy and paste your full file_paths.xml in here?
@jamesmontemagno sure, here you go:
<?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.amtangee.android/files/Pictures" />
<external-path name="my_movies" path="Android/data/com.amtangee.android/files/Movies" />
</paths>
Yeah, that one doesn't work anymore you need to update the scheme to the new way I have documented.
You don't need to specify the full path, that is probalby why it didn't work.
Hmm, I think you got me wrong here. The way you documented doesn't work ("external-files-path" instead of "external-path"). I tried all different kinds of solutions (full path, no full path, different prefixes, etc.), but the one I posted is the only one that worked for me.
could just depend on your settings, if you look at my sample works just fine. https://github.com/jamesmontemagno/MediaPlugin/blob/master/tests/MediaAndroidTest/Resources/xml/file_paths.xml
As long as you have it working that is good :)
Yeah, definitely ;-) But your sample isn't working for me. Maybe device specific? I have a Honor 9... That whole Android fragmentation is really killing me ;-)
I have the same problem on Huawei device
Looks like it's something about this issue https://stackoverflow.com/questions/39895579/fileprovider-error-onhuawei-devices
@jamesmontemagno
why is this issue closed?
The issue seems to be specfic to some huawei devices that have an sd card. In my case, its a p8 lite 2017. We don't seem to have a fix for this, because i think this should be fixed in the plugin. If you take a look at the comment of @milena23 , it contains a link to a stackoverflow post about the issue.
Right now, i don't seem to have a way to fix the issue, as the fix suggested by @obartelt breaks the plugin for other devices
Edit:
After finding this page:
it turns out the fix to have it work on both Huawei and non-huawei devices, i needed to change my file_paths.xml to:
<?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/<my package id>/files/Pictures" />
<external-path name="my_movies" path="Android/data/<my package id>/files/Movies" />
</paths>
so i changed two things.
This seems to be the only way to make it work. Maybe it's a good idea to update the readme and example to match this, so the plugin actually works on all devices
external-files-path to external-path
@PaulVrugt is that so? I haven't had any complaints yet, but who knows how users use the app? ;-)
@obartelt see my updated comment. I've posted an example of the xml that seems to work for all devices
@PaulVrugt thanks, but that seems to be exactly what I have, and what I posted here on Oct 3/5 2017?
@obartelt
Right, now that i read it for the 3rd time I see you are correct. The discussion between you and jamesmontemagno seemed to go specifically about the external-files-path and external-path, and there was no more mentioning about the full path after jamesmontemagno stated you shouldn't use the full path. That's why I didn't understand that this was necessary.
Anyway, good for you that you're already using the method I (and apparently you too ;) ) posted, since this seems to work on all devices.
@jamesmontemagno , this confirms that this seems to be the only working way. Probably a good idea to update the documentation, or provide us with an alternative solution.
Most helpful comment
Have you read my comment? Sorry, it got corrupted somehow. It should've read:
I had the same problem. You need to change the file_paths.xml. It must read:
instead of:
At least that works for me...