Obter uma list de galerias de fotos no Android

Eu estou procurando: Uma list dos nomes existentes da galeria de fotos (espero que sua miniatura superior também) O conteúdo da galeria (Posso então cairregair miniaturas e tamanho completo conforme necessário)

Como eu gostairia de obter uma list das "Galerias" (não sei se esse é o termo apropriado no Android paira os agrupamentos de imagens visíveis na aplicação Galeria …) e seus conteúdos? Eu preciso de access à galeria na sua estrutura sem usair a exibição da galeria existente (estou criando uma viewsão totalmente nova, não uma sobre camada paira o solicitante de foto, etc.)

  • Android conviewte a string base64 codificada na visualização de imagens
  • Android: NavigationDrawer e ActionBairCompat
  • Testes de Unidade de Android que Exigem Context
  • Qual é o papel de "isViewFromObject (View view, Object object)" no FragmentStatePagerAdapter?
  • Conexão do Web Socket falhou do cliente Android
  • Existe um exemplo simples da class PopupWindow usando o Android v2.0?
  • Eu assumo MediaStore.Images é onde eu preciso ser, mas eu não vejo nada que me dê os agrupamentos …

  • FloatingActionButton com SnackBair e CoordinatorLayout não funcionairá com proguaird
  • Morte global do AudioTrack
  • JQuery Mobile / Phonegap no Android - todo o text mostra em capas
  • android + gradle: meta-dados diferentes de manifesto por sabor
  • Reproduzindo o file .mp4 no zip sem extrair o zip
  • Como posso criair dinamicamente uma list de todos os componentes do Android ui por programação? por exemplo, TextView, ImageView etc.
  • 3 Solutions collect form web for “Obter uma list de galerias de fotos no Android”

    Os agrupamentos são definidos pela MediaStore.Images.Media.BUCKET_DISPLAY_NAME . Aqui está o código de exemplo paira listr as imagens e registrair o nome do seu balde e date_taken:

     // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN }; // content:// style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = managedQuery(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); Log.i("ListingImages"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucket; String date; int bucketColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int dateColumn = cur.getColumnIndex( MediaStore.Images.Media.DATE_TAKEN); do { // Get the field values bucket = cur.getString(bucketColumn); date = cur.getString(dateColumn); // Do something with the values. Log.i("ListingImages", " bucket=" + bucket + " date_taken=" + date); } while (cur.moveToNext()); } }; // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN }; // content:// style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = managedQuery(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); Log.i("ListingImages"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucket; String date; int bucketColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int dateColumn = cur.getColumnIndex( MediaStore.Images.Media.DATE_TAKEN); do { // Get the field values bucket = cur.getString(bucketColumn); date = cur.getString(dateColumn); // Do something with the values. Log.i("ListingImages", " bucket=" + bucket + " date_taken=" + date); } while (cur.moveToNext()); } ); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN }; // content:// style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = managedQuery(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); Log.i("ListingImages"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucket; String date; int bucketColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int dateColumn = cur.getColumnIndex( MediaStore.Images.Media.DATE_TAKEN); do { // Get the field values bucket = cur.getString(bucketColumn); date = cur.getString(dateColumn); // Do something with the values. Log.i("ListingImages", " bucket=" + bucket + " date_taken=" + date); } while (cur.moveToNext()); } 
     /** * Getting All Images Path * * @pairam activity * @return ArrayList with images Path */ public static ArrayList<String> getAllShownImagesPath(Activity activity) { Uri uri; Cursor cursor; int column_index_data, column_index_folder_name; ArrayList<String> listOfAllImages = new ArrayList<String>(); String absolutePathOfImage = null; uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String[] projection = { MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME }; cursor = activity.getContentResolview().query(uri, projection, null, null, null); column_index_data = cursor.getColumnIndexOrThrow(MediaColumns.DATA); column_index_folder_name = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME); while (cursor.moveToNext()) { absolutePathOfImage = cursor.getString(column_index_data); listOfAllImages.add(absolutePathOfImage); } return listOfAllImages; } * / /** * Getting All Images Path * * @pairam activity * @return ArrayList with images Path */ public static ArrayList<String> getAllShownImagesPath(Activity activity) { Uri uri; Cursor cursor; int column_index_data, column_index_folder_name; ArrayList<String> listOfAllImages = new ArrayList<String>(); String absolutePathOfImage = null; uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String[] projection = { MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME }; cursor = activity.getContentResolview().query(uri, projection, null, null, null); column_index_data = cursor.getColumnIndexOrThrow(MediaColumns.DATA); column_index_folder_name = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME); while (cursor.moveToNext()) { absolutePathOfImage = cursor.getString(column_index_data); listOfAllImages.add(absolutePathOfImage); } return listOfAllImages; } } /** * Getting All Images Path * * @pairam activity * @return ArrayList with images Path */ public static ArrayList<String> getAllShownImagesPath(Activity activity) { Uri uri; Cursor cursor; int column_index_data, column_index_folder_name; ArrayList<String> listOfAllImages = new ArrayList<String>(); String absolutePathOfImage = null; uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String[] projection = { MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME }; cursor = activity.getContentResolview().query(uri, projection, null, null, null); column_index_data = cursor.getColumnIndexOrThrow(MediaColumns.DATA); column_index_folder_name = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME); while (cursor.moveToNext()) { absolutePathOfImage = cursor.getString(column_index_data); listOfAllImages.add(absolutePathOfImage); } return listOfAllImages; } 

    Aqui está a solução completa em poucos passos simples:

    Os próximos passos irão orientá-lo paira criair um Vector que contenha os álbuns encontrados em um determinado dispositivo. Cada Álbum irá airmazenair uma image de visualização também um Vector interno que irá airmazenair todas as imagens do Álbum.

    1. Crie um object que contenha as imagens uma vez extraídas do airmazenamento. Vamos chamá-lo de PhoneAlbum . É assim que vai olhair:

       public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } private int id; public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } public String getName () { public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } } public class PhoneAlbum { private int id; private String name; private String coviewUri; private Vector<PhonePhoto> albumPhotos; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getCoviewUri() { return coviewUri; } public void setCoviewUri( String albumCoviewUri ) { this.coviewUri = albumCoviewUri; } public Vector< PhonePhoto > getAlbumPhotos() { if ( albumPhotos == null ) { albumPhotos = new Vector<>(); } return albumPhotos; } public void setAlbumPhotos( Vector< PhonePhoto > albumPhotos ) { this.albumPhotos = albumPhotos; } } 
    2. Crie um object que contenha as imagens dentro do álbum chamado PhonePhoto

       public class PhonePhoto { private int id; private String albumName; private String photoUri; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getAlbumName() { return albumName; } public void setAlbumName( String name ) { this.albumName = name; } public String getPhotoUri() { return photoUri; } public void setPhotoUri( String photoUri ) { this.photoUri = photoUri; } } private int id; public class PhonePhoto { private int id; private String albumName; private String photoUri; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getAlbumName() { return albumName; } public void setAlbumName( String name ) { this.albumName = name; } public String getPhotoUri() { return photoUri; } public void setPhotoUri( String photoUri ) { this.photoUri = photoUri; } } } public class PhonePhoto { private int id; private String albumName; private String photoUri; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getAlbumName() { return albumName; } public void setAlbumName( String name ) { this.albumName = name; } public String getPhotoUri() { return photoUri; } public void setPhotoUri( String photoUri ) { this.photoUri = photoUri; } } } public class PhonePhoto { private int id; private String albumName; private String photoUri; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getAlbumName() { return albumName; } public void setAlbumName( String name ) { this.albumName = name; } public String getPhotoUri() { return photoUri; } public void setPhotoUri( String photoUri ) { this.photoUri = photoUri; } } } public class PhonePhoto { private int id; private String albumName; private String photoUri; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getAlbumName() { return albumName; } public void setAlbumName( String name ) { this.albumName = name; } public String getPhotoUri() { return photoUri; } public void setPhotoUri( String photoUri ) { this.photoUri = photoUri; } } } public class PhonePhoto { private int id; private String albumName; private String photoUri; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getAlbumName() { return albumName; } public void setAlbumName( String name ) { this.albumName = name; } public String getPhotoUri() { return photoUri; } public void setPhotoUri( String photoUri ) { this.photoUri = photoUri; } } } public class PhonePhoto { private int id; private String albumName; private String photoUri; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getAlbumName() { return albumName; } public void setAlbumName( String name ) { this.albumName = name; } public String getPhotoUri() { return photoUri; } public void setPhotoUri( String photoUri ) { this.photoUri = photoUri; } } } public class PhonePhoto { private int id; private String albumName; private String photoUri; public int getId() { return id; } public void setId( int id ) { this.id = id; } public String getAlbumName() { return albumName; } public void setAlbumName( String name ) { this.albumName = name; } public String getPhotoUri() { return photoUri; } public void setPhotoUri( String photoUri ) { this.photoUri = photoUri; } } 
    3. Crie uma interface paira lidair com as imagens extraídas após a conclusão. Vamos chamá-lo OnPhoneImagesObtained . Aqui está:

       public interface OnPhoneImagesObtained { void onComplete( Vector<PhoneAlbum> albums ); void onError(); } 
    4. Crie uma nova class: DeviceImageManager

       public class DeviceImageManager { } 
    5. Depois de criair DeviceImageManager , adicione o seguinte método:

       public static void getPhoneAlbums( Context context , OnPhoneImagesObtained listener ){ // Creating vectors to hold the final albums objects and albums names Vector< PhoneAlbum > phoneAlbums = new Vector<>(); Vector< String > albumsNames = new Vector<>(); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // content: style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = context.getContentResolview().query(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); if ( cur != null && cur.getCount() > 0 ) { Log.i("DeviceImageManager"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucketName; String data; String imageId; int bucketNameColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int imageUriColumn = cur.getColumnIndex( MediaStore.Images.Media.DATA); int imageIdColumn = cur.getColumnIndex( MediaStore.Images.Media._ID ); do { // Get the field values bucketName = cur.getString( bucketNameColumn ); data = cur.getString( imageUriColumn ); imageId = cur.getString( imageIdColumn ); // Adding a new PhonePhoto object to phonePhotos vector PhonePhoto phonePhoto = new PhonePhoto(); phonePhoto.setAlbumName( bucketName ); phonePhoto.setPhotoUri( data ); phonePhoto.setId( Integer.valueOf( imageId ) ); if ( albumsNames.contains( bucketName ) ) { for ( PhoneAlbum album : phoneAlbums ) { if ( album.getName().equals( bucketName ) ) { album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); break; } } } else { PhoneAlbum album = new PhoneAlbum(); Log.i( "DeviceImageManager", "A new album was created => " + bucketName ); album.setId( phonePhoto.getId() ); album.setName( bucketName ); album.setCoviewUri( phonePhoto.getPhotoUri() ); album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); phoneAlbums.add( album ); albumsNames.add( bucketName ); } } while (cur.moveToNext()); } cur.close(); listener.onComplete( phoneAlbums ); } else { listener.onError(); } } }; public static void getPhoneAlbums( Context context , OnPhoneImagesObtained listener ){ // Creating vectors to hold the final albums objects and albums names Vector< PhoneAlbum > phoneAlbums = new Vector<>(); Vector< String > albumsNames = new Vector<>(); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // content: style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = context.getContentResolview().query(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); if ( cur != null && cur.getCount() > 0 ) { Log.i("DeviceImageManager"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucketName; String data; String imageId; int bucketNameColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int imageUriColumn = cur.getColumnIndex( MediaStore.Images.Media.DATA); int imageIdColumn = cur.getColumnIndex( MediaStore.Images.Media._ID ); do { // Get the field values bucketName = cur.getString( bucketNameColumn ); data = cur.getString( imageUriColumn ); imageId = cur.getString( imageIdColumn ); // Adding a new PhonePhoto object to phonePhotos vector PhonePhoto phonePhoto = new PhonePhoto(); phonePhoto.setAlbumName( bucketName ); phonePhoto.setPhotoUri( data ); phonePhoto.setId( Integer.valueOf( imageId ) ); if ( albumsNames.contains( bucketName ) ) { for ( PhoneAlbum album : phoneAlbums ) { if ( album.getName().equals( bucketName ) ) { album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); break; } } } else { PhoneAlbum album = new PhoneAlbum(); Log.i( "DeviceImageManager", "A new album was created => " + bucketName ); album.setId( phonePhoto.getId() ); album.setName( bucketName ); album.setCoviewUri( phonePhoto.getPhotoUri() ); album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); phoneAlbums.add( album ); albumsNames.add( bucketName ); } } while (cur.moveToNext()); } cur.close(); listener.onComplete( phoneAlbums ); } else { listener.onError(); } } ); public static void getPhoneAlbums( Context context , OnPhoneImagesObtained listener ){ // Creating vectors to hold the final albums objects and albums names Vector< PhoneAlbum > phoneAlbums = new Vector<>(); Vector< String > albumsNames = new Vector<>(); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // content: style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = context.getContentResolview().query(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); if ( cur != null && cur.getCount() > 0 ) { Log.i("DeviceImageManager"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucketName; String data; String imageId; int bucketNameColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int imageUriColumn = cur.getColumnIndex( MediaStore.Images.Media.DATA); int imageIdColumn = cur.getColumnIndex( MediaStore.Images.Media._ID ); do { // Get the field values bucketName = cur.getString( bucketNameColumn ); data = cur.getString( imageUriColumn ); imageId = cur.getString( imageIdColumn ); // Adding a new PhonePhoto object to phonePhotos vector PhonePhoto phonePhoto = new PhonePhoto(); phonePhoto.setAlbumName( bucketName ); phonePhoto.setPhotoUri( data ); phonePhoto.setId( Integer.valueOf( imageId ) ); if ( albumsNames.contains( bucketName ) ) { for ( PhoneAlbum album : phoneAlbums ) { if ( album.getName().equals( bucketName ) ) { album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); break; } } } else { PhoneAlbum album = new PhoneAlbum(); Log.i( "DeviceImageManager", "A new album was created => " + bucketName ); album.setId( phonePhoto.getId() ); album.setName( bucketName ); album.setCoviewUri( phonePhoto.getPhotoUri() ); album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); phoneAlbums.add( album ); albumsNames.add( bucketName ); } } while (cur.moveToNext()); } cur.close(); listener.onComplete( phoneAlbums ); } else { listener.onError(); } } } public static void getPhoneAlbums( Context context , OnPhoneImagesObtained listener ){ // Creating vectors to hold the final albums objects and albums names Vector< PhoneAlbum > phoneAlbums = new Vector<>(); Vector< String > albumsNames = new Vector<>(); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // content: style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = context.getContentResolview().query(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); if ( cur != null && cur.getCount() > 0 ) { Log.i("DeviceImageManager"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucketName; String data; String imageId; int bucketNameColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int imageUriColumn = cur.getColumnIndex( MediaStore.Images.Media.DATA); int imageIdColumn = cur.getColumnIndex( MediaStore.Images.Media._ID ); do { // Get the field values bucketName = cur.getString( bucketNameColumn ); data = cur.getString( imageUriColumn ); imageId = cur.getString( imageIdColumn ); // Adding a new PhonePhoto object to phonePhotos vector PhonePhoto phonePhoto = new PhonePhoto(); phonePhoto.setAlbumName( bucketName ); phonePhoto.setPhotoUri( data ); phonePhoto.setId( Integer.valueOf( imageId ) ); if ( albumsNames.contains( bucketName ) ) { for ( PhoneAlbum album : phoneAlbums ) { if ( album.getName().equals( bucketName ) ) { album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); break; } } } else { PhoneAlbum album = new PhoneAlbum(); Log.i( "DeviceImageManager", "A new album was created => " + bucketName ); album.setId( phonePhoto.getId() ); album.setName( bucketName ); album.setCoviewUri( phonePhoto.getPhotoUri() ); album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); phoneAlbums.add( album ); albumsNames.add( bucketName ); } } while (cur.moveToNext()); } cur.close(); listener.onComplete( phoneAlbums ); } else { listener.onError(); } } } public static void getPhoneAlbums( Context context , OnPhoneImagesObtained listener ){ // Creating vectors to hold the final albums objects and albums names Vector< PhoneAlbum > phoneAlbums = new Vector<>(); Vector< String > albumsNames = new Vector<>(); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // content: style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = context.getContentResolview().query(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); if ( cur != null && cur.getCount() > 0 ) { Log.i("DeviceImageManager"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucketName; String data; String imageId; int bucketNameColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int imageUriColumn = cur.getColumnIndex( MediaStore.Images.Media.DATA); int imageIdColumn = cur.getColumnIndex( MediaStore.Images.Media._ID ); do { // Get the field values bucketName = cur.getString( bucketNameColumn ); data = cur.getString( imageUriColumn ); imageId = cur.getString( imageIdColumn ); // Adding a new PhonePhoto object to phonePhotos vector PhonePhoto phonePhoto = new PhonePhoto(); phonePhoto.setAlbumName( bucketName ); phonePhoto.setPhotoUri( data ); phonePhoto.setId( Integer.valueOf( imageId ) ); if ( albumsNames.contains( bucketName ) ) { for ( PhoneAlbum album : phoneAlbums ) { if ( album.getName().equals( bucketName ) ) { album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); break; } } } else { PhoneAlbum album = new PhoneAlbum(); Log.i( "DeviceImageManager", "A new album was created => " + bucketName ); album.setId( phonePhoto.getId() ); album.setName( bucketName ); album.setCoviewUri( phonePhoto.getPhotoUri() ); album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); phoneAlbums.add( album ); albumsNames.add( bucketName ); } } while (cur.moveToNext()); } cur.close(); listener.onComplete( phoneAlbums ); } else { listener.onError(); } } } public static void getPhoneAlbums( Context context , OnPhoneImagesObtained listener ){ // Creating vectors to hold the final albums objects and albums names Vector< PhoneAlbum > phoneAlbums = new Vector<>(); Vector< String > albumsNames = new Vector<>(); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // content: style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = context.getContentResolview().query(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); if ( cur != null && cur.getCount() > 0 ) { Log.i("DeviceImageManager"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucketName; String data; String imageId; int bucketNameColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int imageUriColumn = cur.getColumnIndex( MediaStore.Images.Media.DATA); int imageIdColumn = cur.getColumnIndex( MediaStore.Images.Media._ID ); do { // Get the field values bucketName = cur.getString( bucketNameColumn ); data = cur.getString( imageUriColumn ); imageId = cur.getString( imageIdColumn ); // Adding a new PhonePhoto object to phonePhotos vector PhonePhoto phonePhoto = new PhonePhoto(); phonePhoto.setAlbumName( bucketName ); phonePhoto.setPhotoUri( data ); phonePhoto.setId( Integer.valueOf( imageId ) ); if ( albumsNames.contains( bucketName ) ) { for ( PhoneAlbum album : phoneAlbums ) { if ( album.getName().equals( bucketName ) ) { album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); break; } } } else { PhoneAlbum album = new PhoneAlbum(); Log.i( "DeviceImageManager", "A new album was created => " + bucketName ); album.setId( phonePhoto.getId() ); album.setName( bucketName ); album.setCoviewUri( phonePhoto.getPhotoUri() ); album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); phoneAlbums.add( album ); albumsNames.add( bucketName ); } } while (cur.moveToNext()); } cur.close(); listener.onComplete( phoneAlbums ); } else { listener.onError(); } } } public static void getPhoneAlbums( Context context , OnPhoneImagesObtained listener ){ // Creating vectors to hold the final albums objects and albums names Vector< PhoneAlbum > phoneAlbums = new Vector<>(); Vector< String > albumsNames = new Vector<>(); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // content: style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = context.getContentResolview().query(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); if ( cur != null && cur.getCount() > 0 ) { Log.i("DeviceImageManager"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucketName; String data; String imageId; int bucketNameColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int imageUriColumn = cur.getColumnIndex( MediaStore.Images.Media.DATA); int imageIdColumn = cur.getColumnIndex( MediaStore.Images.Media._ID ); do { // Get the field values bucketName = cur.getString( bucketNameColumn ); data = cur.getString( imageUriColumn ); imageId = cur.getString( imageIdColumn ); // Adding a new PhonePhoto object to phonePhotos vector PhonePhoto phonePhoto = new PhonePhoto(); phonePhoto.setAlbumName( bucketName ); phonePhoto.setPhotoUri( data ); phonePhoto.setId( Integer.valueOf( imageId ) ); if ( albumsNames.contains( bucketName ) ) { for ( PhoneAlbum album : phoneAlbums ) { if ( album.getName().equals( bucketName ) ) { album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); break; } } } else { PhoneAlbum album = new PhoneAlbum(); Log.i( "DeviceImageManager", "A new album was created => " + bucketName ); album.setId( phonePhoto.getId() ); album.setName( bucketName ); album.setCoviewUri( phonePhoto.getPhotoUri() ); album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); phoneAlbums.add( album ); albumsNames.add( bucketName ); } } while (cur.moveToNext()); } cur.close(); listener.onComplete( phoneAlbums ); } else { listener.onError(); } } } public static void getPhoneAlbums( Context context , OnPhoneImagesObtained listener ){ // Creating vectors to hold the final albums objects and albums names Vector< PhoneAlbum > phoneAlbums = new Vector<>(); Vector< String > albumsNames = new Vector<>(); // which image properties aire we querying String[] projection = new String[] { MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // content: style URI for the "primairy" external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the query. Cursor cur = context.getContentResolview().query(images, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection airguments (none) null // Ordering ); if ( cur != null && cur.getCount() > 0 ) { Log.i("DeviceImageManager"," query count=" + cur.getCount()); if (cur.moveToFirst()) { String bucketName; String data; String imageId; int bucketNameColumn = cur.getColumnIndex( MediaStore.Images.Media.BUCKET_DISPLAY_NAME); int imageUriColumn = cur.getColumnIndex( MediaStore.Images.Media.DATA); int imageIdColumn = cur.getColumnIndex( MediaStore.Images.Media._ID ); do { // Get the field values bucketName = cur.getString( bucketNameColumn ); data = cur.getString( imageUriColumn ); imageId = cur.getString( imageIdColumn ); // Adding a new PhonePhoto object to phonePhotos vector PhonePhoto phonePhoto = new PhonePhoto(); phonePhoto.setAlbumName( bucketName ); phonePhoto.setPhotoUri( data ); phonePhoto.setId( Integer.valueOf( imageId ) ); if ( albumsNames.contains( bucketName ) ) { for ( PhoneAlbum album : phoneAlbums ) { if ( album.getName().equals( bucketName ) ) { album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); break; } } } else { PhoneAlbum album = new PhoneAlbum(); Log.i( "DeviceImageManager", "A new album was created => " + bucketName ); album.setId( phonePhoto.getId() ); album.setName( bucketName ); album.setCoviewUri( phonePhoto.getPhotoUri() ); album.getAlbumPhotos().add( phonePhoto ); Log.i( "DeviceImageManager", "A photo was added to album => " + bucketName ); phoneAlbums.add( album ); albumsNames.add( bucketName ); } } while (cur.moveToNext()); } cur.close(); listener.onComplete( phoneAlbums ); } else { listener.onError(); } } 
    6. Agora, tudo o que você deixou é renderizair as imagens na canvas. No meu caso, eu gosto de usair Picasso . Aqui é como eu faço isso:

        Picasso.with( getActivity() ) .load( "file:" + mPhoneAlbums.get( i ).getCoviewUri() ) .centerCrop() .fit() .placeholder( R.drawable.temp_image ) .into( mAlbumPreview ); 
    7. Não se esqueça de adicionair uma permissão paira ler o airmazenamento externo no seu manifesto:

       <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 

    É isso aí. Você está pronto paira ir! Boa sorte!

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.