views:

39

answers:

2

hi friends,

I m 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 thats 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??

Helppppp guys...

A: 

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

Fredrik Leijon
wow! Thanx Fredrik... that was really quick... will try it n let u know...
JaVadid
+1  A: 
//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.

Gubatron
wow! i got to try this too... thanx dude...
JaVadid
well Gubatron i dare say... U r perfectly right. Then y didnt my coding work?? ok mayb some small typo fault or something i guess... thanx buddy
JaVadid