Take the 2-minute tour ×

How can I get a user to select from the native gallery in Android, rather than other gallery-like applications such as ASTRO File Manager?

The following code gives a list of activities that can select an image:

Intent intent = new Intent();
List<ResolveInfo> infos = activity.getPackageManager().queryIntentActivities(intent, 0);

If I then do something like this:

activity.startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CHOOSE_IMAGE);

then if the user has more than one application that can act like a gallery (such as ASTRO File Manager), s/he is prompted to select one of them, with no "set as default" option.

I don't want the user to be prompted to choose between them each time, so I'd like to just use the native gallery.

The hacky code sample below uses a whitelist to test for known native gallery names:

    for (ResolveInfo info : infos) {
        if (    0==info.activityInfo.name.compareTo("com.cooliris.media.Gallery")
            ||  0==info.activityInfo.name.compareTo("com.htc.album.CollectionsActivity")
        ) {
            // found the native gallery

Feels kinda dirty. Is there a better way? I suspect I'm missing something in my intent.

share|improve this question
add comment

1 Answer

I didn't get last part of your code.

To start the native gallry what i did is -

    public void upload(){
          Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
          photoPickerIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Pictures/image.jpg"));
          startActivityForResult(photoPickerIntent, 1);


Call the upload() where you like to start the native gallery.

Then to get that image info i did -

 * Retrieves the returned image from the Intent, inserts it into the MediaStore, which
 *  automatically saves a thumbnail. Then assigns the thumbnail to the ImageView.
 *  @param requestCode is the sub-activity code
 *  @param resultCode specifies whether the activity was cancelled or not
 *  @param intent is the data packet passed back from the sub-activity
    super.onActivityResult(requestCode, resultCode, intent);

    if (resultCode == RESULT_CANCELED) {
    else if(resultCode == RESULT_OK) {
        Uri uri = intent.getData();

        String path = getPath(uri);
        Log.i("PATH", path);
        data = path;


   public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        int column_index = cursor
        return cursor.getString(column_index);

If you wouldn't get your answer, clear what you like to do

share|improve this answer
This doesn't work - it doesn't choose from multiple possible installed gallery-like apps - try it with ASTRO installed too. Furthermore, you shouldn't directly reference sdcard these days - instead use Environment.getExternalStorageDirectory() –  Kenton Price Feb 6 '11 at 1:05
add comment

Your Answer


