简体   繁体   English

如何找到Android手机的相机图像文件夹?

[英]How can I find out the camera images folder of an Android phone?

I am developing a camera app for Android. 我正在为Android开发相机应用程序。

One requirement is to save the photos taken to the device's default camera photo folder ie the folder in which Android's native camera stores it. 一项要求是将拍摄的照片保存到设备的默认相机照片文件夹,即Android本机相机存储它的文件夹。

How can I figure out where the native camera is storing the photos it's taking - it is my understanding that this could be different for different makes (Samsung, HTC, Motorola, Sony...) and models (Galaxy Tab, Galaxy S4...) 我如何确定本地相机在哪里存储所拍摄的照片-我的理解是,对于不同品牌(三星,HTC,摩托罗拉,索尼...)和型号(Galaxy Tab,Galaxy S4),这可能会有所不同。 )

Use getExternalStoragePublicDirectory() 使用getExternalStoragePublicDirectory()

with parameter DIRECTORY_PICTURES 参数DIRECTORY_PICTURES

(or, for other use cases, other similar parameters such as DIRECTORY_MOVIES ) (或者,对于其他用例,还使用其他类似的参数,例如DIRECTORY_MOVIES

I know it's a little late for this, but you can do this: 我知道现在有点晚了,但是您可以这样做:

String CameraFolder="Camera";
File CameraDirectory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString());
File[] files = CameraDirectory.listFiles();
for (File CurFile : files) {
      if (CurFile.isDirectory()) {
                CameraDirectory=CurFile.getName();
                break;
      }
}
final String CompleteCameraFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString() + "/" + CameraFolder;

Optionally, you can perform your operation inside the for loop. (可选)您可以在for循环内执行操作。

Additional information on this topic. 关于此主题的其他信息。 You need to add a permission to access the external storage or listFiles() always returns null. 您需要添加访问外部存储的权限,否则listFiles()始终返回null。 Add below to your AndroidManifest.xml 将以下内容添加到您的AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.tomoima.filedirectory"
      xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM