FileProvider error onHuawei devices

前端 未结 4 2060
予麋鹿
予麋鹿 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 02:55

    Try to manually provide the uri

    var fileUri:Uri
    try{
       fileUri = FileProvider.getUriForFile(
                                this,
                                "com.example.android.fileprovider",
                                it
                            )
                        } catch (e:Exception){
                            Log.w("fileProvider Exception","$e")
    
     fileUri=Uri.parse("content://${authority}/${external-path name}/${file name}")
                        }
    
    

    get authority from android:authorites in the provider tag inside AndroidManifest.xml

    get external-path name from name in the external path tag inside file_paths.xml

提交回复
热议问题