Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android list all images available

I am making an application which requires me to list all the images available on the SD-Card of the phone.

I tried querying the ContentResolver way i.e.

Cursor image = getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, new String[]{Images.Media._ID,Images.Media.DATA,Images.Media.DISPLAY_NAME}, null, null, null);

but without any result.

Is there any way i can get the list or if that's not possible then is there any possible intent (e.g. PICK) by which I can allow the user to select a file and then access the path of the file the user selected??

like image 657
JaVadid Avatar asked Jun 11 '10 05:06

JaVadid


People also ask

How do I list items in a Google Photos album?

Items in a particular album or from the user's entire library (the default view in the Google Photos app) can be listed. You can use filters to select photos that match a specified date, content category, or media type when you list items from the user's library.

How to pass custom object to listview in Android Studio?

Custom listview works based on customAdapter. In this custom adapter we can pass custom object. We are passing subject data to listview as shown below. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

What can I do with the Google Photos API?

An important use of the API is to list media items that the user has backed up to Google Photos. Items in a particular album or from the user's entire library (the default view in the Google Photos app) can be listed.

Why is my media item not in my Google Photos library?

If the user has not added an item available in the Sharing tab of their Google Photos to their library, that item is not included in this list. To retrieve a media item, call mediaItems.list.


2 Answers

//where contextObject is your activity
ContentResolver cr = contextObject.getContentResolver();

String[] columns = new String[] {
                ImageColumns._ID,
                ImageColumns.TITLE,
                ImageColumns.DATA,
                ImageColumns.MIME_TYPE,
                ImageColumns.SIZE };
cur = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                columns, null, null, null);

My code is pretty much like yours (except broken down) and it works. You don't need to go about asking the Gallery Intent for stuff, it should work. My two guesses are:

1) Make sure your USB storage is not mounted, if it is you'll see no external images.

2) Maybe a permissions issue? Try adding GLOBAL_SEARCH permission to see if that helps at all.

like image 74
Gubatron Avatar answered Sep 27 '22 19:09

Gubatron


You could use the gallery activity to select images, something like this:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);

in the callback for the activity the file uri will be in the intent parameter

like image 23
Fredrik Leijon Avatar answered Sep 27 '22 18:09

Fredrik Leijon