title: Access photo library - Android application
body: <p>I am developing an application to access the mobile photo library and upload a picture after selecting. The application is loading all the photos perfectly, except pictures taken by the camera.
  Someone might try to help me?</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>import android.content.Intent;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.support.v7.app.ActionBarActivity;
  import android.view.View;
  import android.widget.ImageView;
  
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  
  
  public class MainActivity extends ActionBarActivity {
  
  ImageView img;
  private Bitmap bitmap;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      img = (ImageView) findViewById(R.id.imageView);
      img.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              abrirFoto();
          }
  
      });
  }
  
  public void abrirFoto() {
      Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
      intent.setType("image/*");
      intent.addCategory(Intent.CATEGORY_OPENABLE);
      startActivityForResult(intent, 1);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      InputStream stream = null;
      if (requestCode == 1 &amp;&amp; resultCode == RESULT_OK) {
          try {
              if (bitmap != null) {
                  bitmap.recycle();
              }
              stream = getContentResolver().openInputStream(data.getData());
              bitmap = BitmapFactory.decodeStream(stream);
              img.setImageBitmap(bitmap);
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } finally {
              if (stream != null)
                  try {
                      stream.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
          }
  
      }
  }
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
  android:background="#0B9AE2"&gt;
  
  &lt;ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView"
      android:src="@drawable/fotos1"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true"
      android:layout_weight = "1"/&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textAppearance="?android:attr/textAppearanceMedium"
      android:text="Clique para acessar as fotos do celular"
      android:id="@+id/textView2"
      android:layout_centerHorizontal="true"
      android:layout_weight = "1"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>