Android:FileProvider IllegalArgumentException未能找到包含
我正在尝试使用Android:FileProvider IllegalArgumentException未能找到包含,android,Android,我正在尝试使用FileProvider通过使用intent打开库中的图像。但我得到了以下错误: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.diksha.chatapplication/app_photos/diksha.jpg 我在其他类似的问题中尝试了许多解决方案,但没有一个真正适合我 provider_path.xml A
FileProvider
通过使用intent打开库中的图像。但我得到了以下错误:
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.diksha.chatapplication/app_photos/diksha.jpg
我在其他类似的问题中尝试了许多解决方案,但没有一个真正适合我
provider_path.xml
AndroidManifest.xml
替换:
ContextWrapper cw = new ContextWrapper(getContext().getApplicationContext());
File directory = cw.getDir("photos", Context.MODE_PRIVATE);
与:
FileProvider
不能从使用getDir()创建的任意目录提供服务。它将从getFilesDir()
及其子目录提供服务
而且您很少应该创建ContextWrapper
实例
File directory = new File(getFilesDir(), "photos");