Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] TakePhotoAsync - IllegalArgumentException: failed to find configured root #329

Closed
Knots23 opened this issue Aug 23, 2017 · 20 comments

Comments

@Knots23
Copy link

Knots23 commented Aug 23, 2017

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:

  • issue 312
    • Settings the external path in file_paths.xml to 'Pictures' as specified in the readme throws the exception.
    • Settings the external path in file_paths.xml to 'Android/data/MY_PACKAGE_NAME/files/Pictures' throws the exception.
  • issue 326
    • This seems to occur when you don't add the entries to the manifest / file_paths.xml as specified in the readme.

Bug Information

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

Steps to reproduce the Behavior

Everything should be setup as described in the readme:

  • Target Android SDK is 25, so:
    • xml folder was created under Resources
    • file_paths.xml was created under that xml folder
    • the provider was added to the manifest, where the package name placeholder was replaced with my own package name.

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.

Expected Behavior

The camera dialog will be opened and allows you to take a picture.

Actual Behavior

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.

Code snippet

// Call this from the ICommand
private async Task TakePhoto()
{
   var options = new StoreCameraMediaOption();
   var media = await CrossMedia.Current.TakePhotoAsync(options);
}
@jamesmontemagno
Copy link
Owner

What is your package name? It must be set to something like "com.company.appname"

Rest assured this works fine just try the samples.

@Knots23
Copy link
Author

Knots23 commented Aug 24, 2017

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):

  • Camera
  • Write External Storage
  • Read External Storage

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.

@jamesmontemagno
Copy link
Owner

If you can create a small sample that I can reproduce send it my way to test out.

@obartelt
Copy link

I had the same problem. You need to change the file_paths.xml. It must read:

instead of:

<external-files-path ...>

@mrTR24
Copy link

mrTR24 commented Oct 2, 2017

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 :0 \n at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <61dabd3f0b0446bc8b570d6071d995d7>:0 \n at Android.Support.V4.Content.FileProvider.GetUriForFile (Android.Content.Context context, System.String authority, Java.IO.File file) [0x00078] in <27c17fe440cf491ba8255bcefade6e02>:0 \n at Plugin.Media.MediaPickerActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00212] in C:\projects\mediaplugin\src\Media.Plugin.Android\MediaPickerActivity.cs:172 \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 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+d__48.MoveNext () [0x001b6] in C:\Users\user\Desktop\MyProject 4 Aug\MyProject.Android\MyProject.Android\ViewModel\PhotoAndCommentViewModel.cs:185 \n --- End of managed Java.Lang.IllegalArgumentException stack trace ---\njava.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\tat android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:678)\n\tat android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:377)\n\tat md5a3e164e78ade0c22cefea770ddd0bc49.MediaPickerActivity.n_onCreate(Native Method)\n\tat md5a3e164e78ade0c22cefea770ddd0bc49.MediaPickerActivity.onCreate(MediaPickerActivity.java:42)\n\tat android.app.Activity.performCreate(Activity.java:6956)\n\tat android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)\n\tat android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)\n\tat android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)\n\tat android.app.ActivityThread.-wrap14(ActivityThread.java)\n\tat android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)\n\tat android.os.Handler.dispatchMessage(Handler.java:102)\n\tat android.os.Looper.loop(Looper.java:154)\n\tat android.app.ActivityThread.main(ActivityThread.java:6776)\n\tat java.lang.reflect.Method.invoke(Native Method)\n\tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)\n\tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)\n"

@jamesmontemagno
Copy link
Owner

Can't reproduce

@ghost ghost removed the in-review label Oct 3, 2017
@obartelt
Copy link

obartelt commented Oct 3, 2017

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:

<external-path ...>

instead of:

<external-files-path ...>

At least that works for me...

@jamesmontemagno
Copy link
Owner

@obartelt can you copy and paste your full file_paths.xml in here?

@obartelt
Copy link

obartelt commented Oct 5, 2017

@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>

@jamesmontemagno
Copy link
Owner

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.

@obartelt
Copy link

obartelt commented Oct 6, 2017

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.

@jamesmontemagno
Copy link
Owner

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

@jamesmontemagno
Copy link
Owner

As long as you have it working that is good :)

@obartelt
Copy link

obartelt commented Oct 6, 2017

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 ;-)

@yuliya-loyko
Copy link

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

@PaulVrugt
Copy link

PaulVrugt commented Apr 10, 2018

@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.

  1. i changed external-files-path to external-path
  2. i changed the value of the "path" from Pictures/Movies to the full path

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

@obartelt
Copy link

@PaulVrugt is that so? I haven't had any complaints yet, but who knows how users use the app? ;-)

@PaulVrugt
Copy link

@obartelt see my updated comment. I've posted an example of the xml that seems to work for all devices

@obartelt
Copy link

@PaulVrugt thanks, but that seems to be exactly what I have, and what I posted here on Oct 3/5 2017?

@PaulVrugt
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants