检测 Android 相机文件夹 [英] Detect Android Camera folder

查看:16
本文介绍了检测 Android 相机文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测每台 Android 设备上的相机文件夹.从我读到的内容来看,这个文件夹因制造商而异,并且无法保证设备上什至会有 DCIM 文件夹.

I would like to detect the camera folder on every Android device. From what I've read this folder differs from an manufacturer to another and there is no guarantee that there will be even an DCIM folder on the device.

这是我现在用来获取文件的方法:

This is the method that I'm using to get the files now:

private static final Set<String> FILTER_FOLDERS = new HashSet<String>(
        Arrays.asList(new String[] { "camera", "100andro", "100media" }));


private Set<String> getCameraPictures() {
        final String[] columns = new String[] {
                MediaStore.Images.ImageColumns._ID,
                MediaStore.Images.ImageColumns.DATA,
                MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
                MediaStore.Images.ImageColumns.DISPLAY_NAME,
                MediaStore.Images.ImageColumns.DATE_TAKEN,
                MediaStore.Images.ImageColumns.MIME_TYPE };
        // Order by options - by date & descending
        final String orderBy = MediaStore.Images.ImageColumns.DATE_TAKEN
                + " DESC";
        // Stores all the images from the gallery in Cursor
        final Cursor cursor = getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, // base URI for
                                                                // the Images
                columns, // Which columns to return
                null, // Which rows to return (all rows)
                null, // Selection arguments (none)
                orderBy); // Ordering

        // Total number of images
        int count = cursor.getCount();

        // Create an array to store path to all the images
        String[] picturesPath = new String[count];

        if (cursor.moveToFirst()) {
            int dataColumn = cursor
                    .getColumnIndex(MediaStore.Images.Media.DATA);
            int bucketColumn = cursor
                    .getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);

            do {
                if (FILTER_FOLDERS.contains(cursor.getString(bucketColumn)
                        .toLowerCase(Locale.getDefault()))) {
                    // Store the path of the image
                    picturesPath[cursor.getPosition()] = cursor
                            .getString(dataColumn);
                }
            } while (cursor.moveToNext());
        }
        // Close the cursor
        if (null != cursor) {
            cursor.close();
        }
        return new HashSet<String>(Arrays.asList(picturesPath));
    }

但这也是从其他地方返回的图像......如何仅检索用相机拍摄的图像?如果没有本地方法可以做到这一点,我在哪里可以找到每个制造商使用的文件夹的名称(有多少),以便我可以按 BUCKET_DISPLAY_NAME 过滤它?

But this is returning images from other places also ... How can I retrieve only the images taken with the camera ? If there is no native way to do this, where can I find what are the names for the folders used by each manufacturer (as many as there are) so that I can filter it by BUCKET_DISPLAY_NAME ?

谢谢

乐:

我已经更新了在设备上获取图像的方法 &同时过滤文件夹.

I have updated the method to get the images on device & also filter the folders.

推荐答案

设备附带了数十种甚至数百种相机应用程序,以及数以千计的相机应用程序可供下载.没有人必须使用特定的相机文件夹",也没有人必须让他们的图像被 MediaStore 索引.

There are dozens, perhaps hundreds, of camera apps that ship with devices, to go along with thousands of camera apps available for download. None have to use a particular "camera folder" and none have to have their images indexed by MediaStore.

设备的常规相机文件夹"将位于 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) 指定的位置.如果没有相机应用程序使用该目录,则该目录可能还不存在.但是,同样,相机应用并没有要求使用它——它们可以将图像存储在任何他们想要的地方,包括您无法访问的地方(例如,内部存储、云").

The conventional "camera folder" for a device will be in the location specified by Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM). That directory might not exist yet, if no camera app has used it. But, again, there is no requirement that a camera app use it -- they can store their images wherever they want to, including places that you cannot access (e.g., internal storage, "the cloud").

我怎样才能只检索用相机拍摄的图像?

How can I retrieve only the images taken with the camera ?

你不能.地球上有超过 10 亿部智能手机,任何手机上都可以有任何其他手机上的任何相机拍摄的照片,这要归功于照片共享应用程序和网站.这是在智能手机以外的相机拍摄的照片之上.为了您的利益,不需要以某种方式指定由设备自己的相机拍摄的图像.

You can't. There are well over one billion smartphones on the planet, and any phone could have pictures on it taken by any camera from any other phone, courtesy of photo-sharing apps and sites. This is on top of pictures taken by cameras other than smartphones. There is no requirement that images taken by the device's own camera need to be somehow designated as such for your benefit.

这篇关于检测 Android 相机文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆