Android

안드로이드 갤러리 모든 불러오기 Cursor ( Android q )

Machine_웅 2021. 9. 3. 12:18
728x90
반응형
public void  getAllPhotos(){

        ArrayList<Uri> uriArr = new ArrayList<Uri>();

        String[] projection = new String[]{
                MediaStore.Images.ImageColumns._ID,
                MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, //the album it in
                MediaStore.Images.ImageColumns.DATE_TAKEN,
                MediaStore.Images.ImageColumns.MIME_TYPE
        };
        Cursor cursor =context.getContentResolver()
                .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        projection,
                        null,
                        null,
                        MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");


        if(cursor != null){
            while (cursor.moveToNext()){
                int idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID);
                long id = cursor.getLong(idColumn);

                wLog.LogD("idColumn : " + idColumn);
                wLog.LogD("id : " + id);
                Uri uri =  Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,String.valueOf(id));
                wLog.LogD("uri : " + uri);
                uriArr.add(uri);
            }
        }
        cursor.close();
    }
728x90
반응형