如何使用MediaStore显示在GridView中的所有图片 [英] How to Use MediaStore to display all images in GridView

查看:318
本文介绍了如何使用MediaStore显示在GridView中的所有图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要想弄清楚,我有一个问题一点帮助。我有一个将查询手机上的所有图像,并在GridView中显示它们的应用程序。我能做到这一点,填充列表。问题是,当我访问列表,并获得从一个查询的项目信息。光标告诉我,该项目已的文件路径

I need a little help in trying to figure out a problem that I am having. I have an application that will query all the images on the phone and display them in a GridView. I was able to do this and populate the list. The problem is when I am accessing the list and getting information from the items from a query. The cursor is telling me that the item has a file path of

/mnt/sdcard/images/media/file.jpg

/mnt/sdcard/images/media/file.jpg

但路径是唯一

/sdcard/images/media/file.jpg

/sdcard/images/media/file.jpg

这是code我用填充列表。

This is the code I used to populate the list.

        // Set up an array of the Thumbnail Image ID column we want
        String[] projection = {MediaStore.Images.Thumbnails._ID};
        // Create the cursor pointing to the SDCard
        //returns the cursor that checks the sdcard for Thumbnail id's
              cursor = managedQuery( 
                MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                projection, 
                // Which columns to return
                null,
                // Return all rows
                null,
                MediaStore.Images.Thumbnails.IMAGE_ID);
              // Get the column index of the Thumbnails Image ID
              columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);

该项目实际上已显示,但该路径是错误的,当我从另一个游标检索。
??????
我有点失落。

The items DO ACTUALLY display but the path is wrong when I retrieve them from another cursor. ?????? I am a bit lost.

我在模拟器和我的物理设备上使用它。同样的问题。
我得到一个错误,指出路径为NULL和程序崩溃。

I have used it in emulator and on my physical device. Same problem. I get an ERROR stating that the path is NULL and the program crashed.

有没有一种方法,我可以得到MediaStore查询EXTERNAL_CONTENT_URI并给予正确的道路,我需要?
此外,当我用它我的身体电话,查询时对我的SD卡与图像的第一个目录,然后停下来,和生活方式它来查询多个目录?

Is there a way that I can get the MediaStore to query the EXTERNAL_CONTENT_URI and give the correct path I need? Also, when I used it on my physical phone, the query when to the first directory on my sdcard with images then stopped, and way for it to query more directories?

推荐答案

你有没有尝试 MediaStore.Images.Media.EXTERNAL_CONTENT_URI

还有 managedQuery()是pcated德$ P $,使用 getContentResolver()查询()

Also managedQuery() is deprecated, use getContentResolver().query().

这篇关于如何使用MediaStore显示在GridView中的所有图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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