FileProvider error onHuawei devices

前端 未结 4 2138
予麋鹿
予麋鹿 2021-01-31 02:27

I have an exception that happens only on Huawei devices in my app when using FileProvider.getUriForFile:

Exception: java.lang.Illeg         


        
4条回答
  •  误落风尘
    2021-01-31 03:17

    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.

提交回复
热议问题