1

I am using context.getExternalFilesDir to obtain the app's folder and that is on majority of devices the internal storage emulated card: /storage/emulated/0/Android/data/mypackage.com/files

This is true and as per docs:

Returns the absolute path to the directory on the primary shared/external storage device where the application can place persistent files it owns.

Now, in a folder created on that getExternalFilesDir returned, I have a file myimage.png which I want to share with another app, calling FileProvider.getUriForFile(...myimage.png) throws an error on some devices and the error is like:

Failed to find configured root that containts /storage/1234-1234/Android/data/mypackage.com/files

I have 2 questions:

  1. what could cause to see the sdcard as getExternalFilesDir and not the internal storage path? I was not able to see it on my device, even if I have a sd card inserted in my device. Since the internal storage should be first to be returned.

  2. Why does getUriForFile crash when using the path from external sdcard and how to fix it?

My files path contains <external-files-path > entry and works fine with no crash when using the storage/emulated/0/Android path

I saw some answer at FileProvider error onHuawei devices that some devices return the path differently on ContextCompat.getExternalFilesDirs and other mention (https://github.com/linchaolong/ImagePicker/issues/10) that the getUriForFile uses internally the ContextCompat.getExternalFilesDirs call.

Alin
  • 14,809
  • 40
  • 129
  • 218
  • I don't see any evidence the `getExternalFilesDir` is returning a path to removeable storage as you claim. You say "probably sd card". Why do you think that? – Jeffrey Blattman Oct 31 '18 at 21:55
  • I've added more insight on the error. The error shows a path which is different from the `/storage/emulated/0/Android` and has in it something that looks like the sd card's name. I say this because if I query the ExternalFilesDirs[] on a device, the sd card in it also has a similar name and path – Alin Oct 31 '18 at 22:38
  • 1
    I'd suggest re-wording your question. You might get more traction if you just describe the actual problem you are having and do not assume a root cause. – Jeffrey Blattman Nov 01 '18 at 16:15

0 Answers0