Android 上是否有 API 调用来获取相机应用程序存储录制视频的文件夹的路径?我目前正在使用此代码段,但想知道是否有合适(更清洁)的方法来执行此操作?
// check file path exists!
File f = new File(Environment.getExternalStorageDirectory() + "/Videos");
if (!f.isDirectory()) {
f = new File(Environment.getExternalStorageDirectory() + "/DCIM");
if (!f.isDirectory()) {
f = new File(Environment.getExternalStorageDirectory() + "/");
}
}
String path = f.getAbsolutePath().toString();
编辑:
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
返回
/storage/emulated/0/DCIM
但是,
| => adb shell
shell@d2can:/ $ cd /storage/emulated
shell@d2can:/storage/emulated $ ls
legacy
shell@d2can:/storage/emulated $ cd 0
/system/bin/sh: cd: /storage/emulated/0: No such file or directory
2|shell@d2can:/storage/emulated $
奇怪的是,如果我真的继续尝试在那个不存在的位置(从 android 应用程序中)创建文件,它们确实会在 /sdcard/DCIM
中创建!!然而,当使用调试器检查应用程序变量时,它们具有如上所示的路径 - 无效路径。
最佳答案
Is there an API call on Android to get the path to the folder where the Camera app stores the recorded videos?
没有“相机应用”。 Android 设备型号有数千种。这些设备型号预装了数十个(如果不是数百个)相机应用程序。用户可以从 Play 商店或其他地方下载数百(如果不是数千)其他相机应用程序。
无需将录制的视频保存在任何特定位置,更不用说您可以通过 Java 文件 I/O 访问的位置了。
I'm currently using this snippet but was wondering if there's a proper (cleaner) way to do this?
您可以获得设备建议将文件存储在外部存储器上的位置via Environment.getExternalStoragePublicDirectory()
.具体来说,DIRECTORY_DCIM
被描述为“将设备安装为相机时的图片和视频的传统位置”。
但是:
相机应用不需要使用此目录
关注
DIRECTORY_DCIM
的相机应用通常会创建一个特定于应用的子目录
关于android:获取媒体文件夹(用于视频),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33784820/