Android: How to query a list of bucket name

前端 未结 5 1859
后悔当初
后悔当初 2020-12-30 06:53

I want to retrieve only the name of the bucket (Albums). E.g. Camera, Download etc but not a list of Camera, Download etc from all the the photos so how do I retrieve one ro

5条回答
  •  隐瞒了意图╮
    2020-12-30 07:43

    Here it is. it works for me:

    Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        String[] projection = new String[]{   
                MediaStore.Images.Media.BUCKET_ID,
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
                MediaStore.Images.Media.DATE_TAKEN,
                MediaStore.Images.Media.DATA
        };
    
        String BUCKET_ORDER_BY = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
        String BUCKET_GROUP_BY = "1) GROUP BY 1,(2";
        Cursor imagecursor = managedQuery(images,
                projection, // Which columns to return
                BUCKET_GROUP_BY,       // Which rows to return (all rows)
                null,       // Selection arguments (none)
                BUCKET_ORDER_BY        // Ordering
                );
    
        this.imageUrls = new ArrayList();
        this.imageBuckets  = new ArrayList();
        for (int i = 0; i < imagecursor.getCount(); i++)
        {
            imagecursor.moveToPosition(i);
            int bucketColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
            String bucketDisplayName = imagecursor.getString(bucketColumnIndex);
            imageBuckets.add(bucketDisplayName);
            int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
            imageUrls.add(imagecursor.getString(dataColumnIndex));
    
        }
    

    imageBuckets Arraylist is containing album names

    imageUrls Arraylist is containing path of last modifided image of album you can use it as thumbnail

提交回复
热议问题