Open chrisaut opened 7 years ago
@chrisaut I without huawei andriod n device, did you fix it? I think it's better to be part of the picker
Is this bug fixed?
Currently I had the same problem in my own app. This was how I fixed it:
Because FileProvider.getUriForFile(...) uses internally ContextCompat.getExternalFilesDirs(..). Now, when we use Context.getExternalFilesDir(..) it will crash on some Huawei devices. This is because Huawei devices and the Android documentation of Context.getExternalFilesDir(..) are inconsistent. (more here: https://stackoverflow.com/questions/39895579/fileprovider-error-onhuawei-devices).
I just take care I am going to use also ContextCompat.getexternalFilesDirs(..) instead of Context.getExternalFilesDir(..). This way, everything works fine for me.
public static File getExternalFilesDir(Context context) {
// IMPORTANT TO USE THIS METHOD, INSTEAD OF Context.getExternalFilesDir(..)!!!!
// There is a bug on Huawei-Devices, which select the wrong external path.
// More info here: https://stackoverflow.com/questions/39895579/fileprovider-error-onhuawei-devices
File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null);
if (externalFilesDirs.length > 0) {
return externalFilesDirs[0];
} else {
return null;
}
}
@hubermichael88 Hi, where did u implement this solution ? Can you please give a more detailed example? Thank you!
It is more a workaround, better would be to fix it within the picker. Just make sure you NEVER call "Context.getExternalFilesDir(..) in your own app-code, use instead the method above which makes sure to get the right external path.
@jppavez you can new a custom provider
I'm seeing crash reports as follows:
They all seem to come from Huawei devices running Android 7.
I found this stackoverflow thread discussing the issue https://stackoverflow.com/questions/39895579/fileprovider-error-onhuawei-devices but frankly I don't know if it's possible to implement these workarounds from outside the picker code itself, or if this needs to be done as part of the picker?
Any advice?