Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:FileProvider IllegalArgumentException未能找到包含_Android - Fatal编程技术网

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");