Android How to - Start the system gallery activity to pick an image








Question

We would like to know how to start the system gallery activity to pick an image.

Answer

import android.app.Activity;
import android.content.Intent;
public class Main{
/*from   w  w w  .j av a  2  s .  co  m*/
  /**
   * Start the system gallery activity to pick an image
   */
  public static void pickFromGallery(Activity activity) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");

    Intent chooser = Intent.createChooser(intent, "Choose a Picture");
    int requestCode = 10086;
    activity.startActivityForResult(chooser, requestCode);
  }

}