Android 设备特定相机路径问题
我知道我的问题与这个问题和这个。但我仍然有一些问题,所以不要试图关闭或否决我的问题朋友。请完整地回答这个问题。
在我的应用程序中,我想将图像存储到与设备本机相机存储图像的文件夹相同的文件夹中。根据我的研究,我发现每个设备将图像存储到不同的名称和不同的文件夹中。
即:
Nexus-One 将其相机文件存储到名为
Camera
的文件夹(/sdcard/DCIM/Camera)。所有 HTC 设备都将其相机文件存储到名为
100MEDIA (/sdcard/DCIM/100MEDIA)。
索尼 Xperia x10 将其相机文件存储到名为
100ANDRO
的文件夹(/sdcard/DCIM/100ANDRO)。Motorola MilesStone 将其相机文件存储到名为
的文件夹中相机
(/sdcard/DCIM/Camera)。
所以我想知道是否可以通过编程方式获取此路径,以便我可以将从应用程序拍摄的图像存储到同一位置?
当我在谷歌搜索时,我发现最好创建一个自己的外部文件夹,以便我可以使用我指定的名称将图像存储在该路径中。之后,在 API 版本 3 (Android 1.5) 的 HTC 设备中,我发现仅创建了文件夹,但图像以自己的名称保存在默认位置。
如何解决这个问题?是否无法找到为每个设备保存的图像的具体路径和名称?请朋友们帮助我。
I know that my question is a duplicate of this question and this one. But still I have some problems, so don't try to close or downvote my question friends. Please go through the question fully.
In my app I want to store Images into the same folder as where the device native Camera stores them. As per my research, I have found out that each device stores the Images into a different name and in different folder.
That is:
Nexus-One stores its camera files into a folder named
Camera
(/sdcard/DCIM/Camera).All HTC devices store their camera files into a folder named
100MEDIA
(/sdcard/DCIM/100MEDIA).Sony Xperia x10 stores its camera files into a folder named
100ANDRO
(/sdcard/DCIM/100ANDRO).Motorola MilesStone stores its camera files into a folder named
Camera
(/sdcard/DCIM/Camera).
So I wanted to know if it's programmatically possible to get this path so that I can store the images taken from my app to the same location?
When I was googling I found out that it's better to create an external folder of my own so that I can store the images in that path with the name I am specifying. After that also in HTC device of API version 3 (Android 1.5) I found out that only the folder is getting created but the image gets saved in its default place with a name of its own.
How to solve this issue? Is it not possible to find the specific path and name of the image that gets saved for each device? Please help me friends.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 API 级别低于 7,请使用 getExternalStorageDirectory(),然后附加 /Pictures 来获取照片存储的路径。
对于API级别> 7.使用getExternalStoragePublicDirectory(DIRECTORY_PICTURES)。
Use getExternalStorageDirectory() if API level is below 7 and then append /Pictures to get the path of Photos storage.
for API level > 7 use getExternalStoragePublicDirectory (DIRECTORY_PICTURES).
我使用以下代码
Where Utils:
编辑:不幸的是,上面的方法可能并不总是有效:(...
最终我做了手动检查:
I use the following code
Where Utils:
EDIT: Unfortunatelly, the approach above may not always work :( ...
Eventually I did manual checkings:
这是我正在使用的功能。它没有具体命名 100Media 或 Camera 目录。它只是从 /DCIM 文件夹开始并查看其子文件夹。如果子目录不是 .thumbnails 目录(或者是,取决于您在做什么),则查看其子目录并获取它们。它还获取 /DCIM 目录本身中的图片。
我自己一直在寻找解决这个问题的方法。由于不同的制造商对相机文件夹有不同的命名约定,因此这似乎可以最好地涵盖所有内容。它对我来说非常有效。
This is the function that I am using. It doesnt specifically name 100Media or Camera directories. It simply starts in the /DCIM folder and looks at its children. If the child is not a .thumbnails directory (or is, depending on what youre doing), then look at its children and get them. It also gets pictures in the /DCIM directory itself.
I have been looking for a solution to this problem myself. Since different manufacturers have differnet naming conventions for camera folders, this seems to cover all ground best. It works for me pretty well.