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:
what could cause to see the sdcard as
getExternalFilesDirand 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.Why does
getUriForFilecrash 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.