遍历安卓系统的图片

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/hnlgzb/article/details/88582950
ContentResolver cr = MainActivity.this.getContentResolver();
Cursor cursor = cr.query(
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null,
        null, "date_modified DESC");
            cursor.moveToFirst();
            String[] strings= cursor.getColumnNames();
            for (String s:strings){
                 int t= cursor.getType(cursor.getColumnIndex(s));

                Log.i("YYY","--:"+s+"--:"+t);

                int id=cursor.getInt(cursor.getColumnIndex("_id"));
                int size=cursor.getInt(cursor.getColumnIndex("_size"));
                int modified=cursor.getInt(cursor.getColumnIndex("date_modified"));
                int datetoken=cursor.getInt(cursor.getColumnIndex("datetaken"));
                int width=cursor.getInt(cursor.getColumnIndex("width"));
                int height=cursor.getInt(cursor.getColumnIndex("height"));
                int mini_thumb_magic=cursor.getInt(cursor.getColumnIndex("mini_thumb_magic"));


                String data=cursor.getString(cursor.getColumnIndex("_data"));
                String display_name=cursor.getString(cursor.getColumnIndex("_display_name"));
                String mime_type=cursor.getString(cursor.getColumnIndex("mime_type"));
                String title=cursor.getString(cursor.getColumnIndex("title"));
                String bucket_id=cursor.getString(cursor.getColumnIndex("bucket_id"));
                String bucket_display_name=cursor.getString(cursor.getColumnIndex("bucket_display_name"));

                String description=cursor.getString(cursor.getColumnIndex("description"));

                String picasa_id=cursor.getString(cursor.getColumnIndex("picasa_id"));



                Log.i("YYY","id:"+id+"---size:"+size+"---modified:"+modified+"--datetaken:"+datetoken+"---width:"+width+
                        "---height:"+height+"--mini thumb magiv:"+mini_thumb_magic+"---data:"+data+"--display name:"+display_name
                +"--mini type:"+mime_type+"=----title:"+title+"---bucket_id:"+bucket_id+"---bucket display name:"+bucket_display_name
                +"--description:"+description+"---picaser_id :"+picasa_id);
//                cursor.get


            }
03-15 19:32:27.066  2663  2734 I YYY     : --:_id--:1
03-15 19:32:27.066  2663  2734 I YYY     : --:_data--:3
03-15 19:32:27.066  2663  2734 I YYY     : --:_size--:1
03-15 19:32:27.066  2663  2734 I YYY     : --:_display_name--:3
03-15 19:32:27.066  2663  2734 I YYY     : --:mime_type--:3
03-15 19:32:27.066  2663  2734 I YYY     : --:title--:3
03-15 19:32:27.066  2663  2734 I YYY     : --:date_added--:1
03-15 19:32:27.066  2663  2734 I YYY     : --:date_modified--:1
03-15 19:32:27.066  2663  2734 I YYY     : --:description--:0
03-15 19:32:27.066  2663  2734 I YYY     : --:picasa_id--:0
03-15 19:32:27.066  2663  2734 I YYY     : --:isprivate--:0
03-15 19:32:27.066  2663  2734 I YYY     : --:latitude--:0
03-15 19:32:27.066  2663  2734 I YYY     : --:longitude--:0
03-15 19:32:27.066  2663  2734 I YYY     : --:datetaken--:1
03-15 19:32:27.066  2663  2734 I YYY     : --:orientation--:1
03-15 19:32:27.066  2663  2734 I YYY     : --:mini_thumb_magic--:0
03-15 19:32:27.067  2663  2734 I YYY     : --:bucket_id--:3
03-15 19:32:27.067  2663  2734 I YYY     : --:bucket_display_name--:3
03-15 19:32:27.067  2663  2734 I YYY     : --:width--:1
03-15 19:32:27.067  2663  2734 I YYY     : --:height--:1
03-15 19:58:36.276  5337  5489 I YYY     : --:_id--:1
03-15 19:58:36.277  5337  5489 I YYY     : id:635808---size:8835648---modified:1552627965--datetaken:2144771395---width:4032---height:3024--mini thumb magiv:0---data:/storage/emulated/0/DCIM/Camera/IMG_20190315_133245.jpg--display name:IMG_20190315_133245.jpg--mini type:image/jpeg=----title:IMG_20190315_133245---bucket_id:-1739773001---bucket display name:Camera--description:null---picaser_id :null
03-15 19:58:36.277  5337  5489 I YYY     : --:_data--:3

参考 返回的类型 

    /**
     * Contains meta data for all available images.
     */
    public static final class Images {
        public interface ImageColumns extends MediaColumns {
            /**
             * The description of the image
             * <P>Type: TEXT</P>
             */
            public static final String DESCRIPTION = "description";

            /**
             * The picasa id of the image
             * <P>Type: TEXT</P>
             */
            public static final String PICASA_ID = "picasa_id";

            /**
             * Whether the video should be published as public or private
             * <P>Type: INTEGER</P>
             */
            public static final String IS_PRIVATE = "isprivate";

            /**
             * The latitude where the image was captured.
             * <P>Type: DOUBLE</P>
             */
            public static final String LATITUDE = "latitude";

            /**
             * The longitude where the image was captured.
             * <P>Type: DOUBLE</P>
             */
            public static final String LONGITUDE = "longitude";

            /**
             * The date & time that the image was taken in units
             * of milliseconds since jan 1, 1970.
             * <P>Type: INTEGER</P>
             */
            public static final String DATE_TAKEN = "datetaken";

            /**
             * The orientation for the image expressed as degrees.
             * Only degrees 0, 90, 180, 270 will work.
             * <P>Type: INTEGER</P>
             */
            public static final String ORIENTATION = "orientation";

            /**
             * The mini thumb id.
             * <P>Type: INTEGER</P>
             */
            public static final String MINI_THUMB_MAGIC = "mini_thumb_magic";

            /**
             * The bucket id of the image. This is a read-only property that
             * is automatically computed from the DATA column.
             * <P>Type: TEXT</P>
             */
            public static final String BUCKET_ID = "bucket_id";

            /**
             * The bucket display name of the image. This is a read-only property that
             * is automatically computed from the DATA column.
             * <P>Type: TEXT</P>
             */
            public static final String BUCKET_DISPLAY_NAME = "bucket_display_name";
        }

猜你喜欢

转载自blog.csdn.net/hnlgzb/article/details/88582950