I have an exception that happens only on Huawei devices in my app when using FileProvider.getUriForFile
:
Exception: java.lang.Illeg
I had the same issue and my solution in the end was to always use the ContextCompat.getExternalFilesDirs
call to build the File
that is used as parameter for FileProvider
.
That way you don't have to use any of the above workarounds.
In other words. If you have control over the File
parameter that you use to call FileProvider
and/or you don't care that the file might end up being saved outside of the classic /storage/emulated/0/Android/data/
folder (which should be perfectly fine, as it's all just the same SD card) then I suggest to do what I have done.
If it's not your case, then I suggest to use the above answer with custom getUriForFile
implementation.