如何从SD卡文件夹的子文件夹中获取图像?

发布于 2024-12-23 02:18:17 字数 278 浏览 1 评论 0原文

以下代码用于从特定文件夹获取图像,但如何获取 sdcard 文件夹的子文件夹图像。

Cursor actualimagecursor = managedQuery(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,
    MediaStore.Images.Media.DATA + " like ? ",
    new String[] { "%unzipped%" }, null);

抱歉英语沟通不好。

Following code is used to get images from particular folder but how to get sub folder's images of sdcard's folder.

Cursor actualimagecursor = managedQuery(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,
    MediaStore.Images.Media.DATA + " like ? ",
    new String[] { "%unzipped%" }, null);

Sorry for bad English communication.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南薇 2024-12-30 02:18:17

尝试使用以下代码

public void searchImageFromSpecificDirectory() {

        String path = null;

        String uri = MediaStore.Images.Media.DATA;
        // if GetImageFromThisDirectory is the name of the directory from which image will be retrieved
        String condition = uri + " like '%/GetImageFromThisDirectory/%'";
        String[] projection = { uri, MediaStore.Images.Media.DATE_ADDED,
                MediaStore.Images.Media.SIZE };
        Vector additionalFiles = null;
        try {
            if (additionalFiles == null) {
                additionalFiles = new Vector<String>();
            }



            Cursor cursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
                    condition, null, null);
            if (cursor != null) {

                boolean isDataPresent = cursor.moveToFirst();

                if (isDataPresent) {

                    do {

                        path = cursor.getString(cursor.getColumnIndex(uri));
System.out.println("...path..."+path);
additionalFiles.add(path);
            }while(cursor.moveToNext());
                }
            if (cursor != null) {
                cursor.close();
            }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Try with the following code

public void searchImageFromSpecificDirectory() {

        String path = null;

        String uri = MediaStore.Images.Media.DATA;
        // if GetImageFromThisDirectory is the name of the directory from which image will be retrieved
        String condition = uri + " like '%/GetImageFromThisDirectory/%'";
        String[] projection = { uri, MediaStore.Images.Media.DATE_ADDED,
                MediaStore.Images.Media.SIZE };
        Vector additionalFiles = null;
        try {
            if (additionalFiles == null) {
                additionalFiles = new Vector<String>();
            }



            Cursor cursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
                    condition, null, null);
            if (cursor != null) {

                boolean isDataPresent = cursor.moveToFirst();

                if (isDataPresent) {

                    do {

                        path = cursor.getString(cursor.getColumnIndex(uri));
System.out.println("...path..."+path);
additionalFiles.add(path);
            }while(cursor.moveToNext());
                }
            if (cursor != null) {
                cursor.close();
            }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
莫相离 2024-12-30 02:18:17

尝试下面的代码:在图像文件夹中包含示例子文件夹。

Cursor cursor = managedQuery(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null,Images.Media.DATA + " like '/mnt/sdcard/Images/Sample%'", null, null);

while (cursor.moveToNext()) {
            System.out.println(cursor.getString(cursor.getColumnIndex(Images.Media.DATA)));
            System.out.println(cursor.getString(cursor.getColumnIndex(Images.Media.DISPLAY_NAME)));

}

Try this code below : In images folder contains Sample sub folder.

Cursor cursor = managedQuery(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null,Images.Media.DATA + " like '/mnt/sdcard/Images/Sample%'", null, null);

while (cursor.moveToNext()) {
            System.out.println(cursor.getString(cursor.getColumnIndex(Images.Media.DATA)));
            System.out.println(cursor.getString(cursor.getColumnIndex(Images.Media.DISPLAY_NAME)));

}
め七分饶幸 2024-12-30 02:18:17

我想给你一个建议,看看你是否想观看某个特定的目录,假设/sdcard/。然后使用 FileObserver 类并使其对每个子目录递归。它肯定会对您有所帮助。尝试一下。创建 stack 或 ArrayList,将所有目录存储在 /sdcard/ 中,然后开始监视所有目录。

I wanna give you one suggestion, See if you want to watch a particular Directory suppose /sdcard/. Then Use FileObserver class and make it recursive for every subdirectory. It will help you for sure. Try it.Make stack or ArrayList which will store all the directories in /sdcard/ and than startWatching for all directories.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文