你好,我想从相机捕捉图像,并存储在特定的文件夹中。为了前夫。我有一个名为"MyImages“的文件夹,我想要将名称为abc.png的捕获图像存储到这个文件夹中,那么我如何设置path of FileProvider来跟踪代码片段。
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_images" path="???"/>
...
下面是我创建图像文件的代码。
public File getAlbumDir() {
File storageDir = null;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
storageDir = new File(Environment.getExternalStorageDirectory(),
"MyImages");
if (storageDir != null) {
if (!storageDir.mkdirs()) {
if (!storageDir.exists()) {
Log.d("CameraSample", "failed to create directory");
return null;
}
}
}
} else {
Log.v(context.getString(R.string.app_name), "External storage is not mounted " +
"READ/WRITE.");
}
return storageDir;
}
public File createImageFile() {
// Create an image file name
String imageFileName = "abc.jpg";
File albumF = getAlbumDir();
File imageF = new File(albumF, imageFileName);
return imageF;
}发布于 2017-05-15 13:18:39
你让MyImages/离开了Environment.getExternalStorageDirectory()。
首先,这不是存放文件的好地方。这类似于在C:\根目录下创建一个目录。
尽管如此,在FileProvider XML配置中,您需要:
<external-path name="my_images" path="MyImages"/>https://stackoverflow.com/questions/43980325
复制相似问题