title: How to get an image from gallery (or drawable) to update an ImageView?
body: <p>in my code I use an intent to take a picture, but I really don't understand where I can get this image after that. My goal in this little application is to take a picture and then to update an ImageView with this picture (and to open google maps with an other intent). The two fonctions are activated with 2 buttons. </p>
  
  <p>MainActivity.java :</p>
  
  <pre><code>import android.net.Uri;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.EditText;
  
  public class MainActivity extends AppCompatActivity {
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      static final int REQUEST_IMAGE_CAPTURE = 1;
  
      public void activerCamera(View view) {
          Intent prendrePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          if (prendrePhoto.resolveActivity(getPackageManager()) != null) {
              startActivityForResult(prendrePhoto, REQUEST_IMAGE_CAPTURE);
          }
      }
  
      public void googleMaps(View view) {
          EditText nameField = (EditText) findViewById(R.id.name_field);
          String name = nameField.getText().toString();
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(Uri.parse("geo:" + name));
          if (intent.resolveActivity(getPackageManager()) != null) {
              startActivity(intent);
          }
      }
  }
  </code></pre>
  
  <p>My activity_main.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 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:orientation="vertical"
      tools:context="com.example.android.photoapp.MainActivity"&gt;
  
  
      &lt;EditText
          android:id="@+id/name_field"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:hint="Exemple : 47.6, -122.3"
          android:layout_gravity="center_horizontal"
          android:layout_marginTop="24dp"/&gt;
  
      &lt;Button
          android:layout_marginTop="24dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Aller sur google maps"
          android:layout_gravity="center_horizontal"
          android:textAllCaps="true"
          android:onClick="googleMaps"/&gt;
      &lt;Button
          android:layout_marginTop="24dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Prendre une photo"
          android:layout_gravity="center_horizontal"
          android:textAllCaps="true"
          android:onClick="activerCamera"/&gt;
  
      &lt;ImageView
          android:id="@+id/imageFondEcran"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I saw in a lot of forum and tutorial some method like this (down), but i cannot make it work properly</p>
  
  <pre><code>@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (data != null) {
          Uri photoUri = data.getData();
          // Do something with the photo based on Uri
          Bitmap selectedImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), photoUri);
          // Load the selected image into a preview
          ImageView ivPreview = (ImageView) findViewById(R.id.ivPreview);
          ivPreview.setImageBitmap(selectedImage);   
      } }
  </code></pre>