title: Uploading an image from phone storage
body: <p>I am trying to make a user upload an image file from his/her phone gallery into my app. I have managed to invoke the gallery but as the user selects an image. I get the following error:</p>
  
  <pre><code>java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://media/external/images/media/7963 (has extras) }} to activity {com.progrmor.tombstone.android/com.progrmor.tombstone.android.AndroidLauncher}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/7963 from pid=16802, uid=10409 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
          at android.app.ActivityThread.deliverResults(ActivityThread.java:4060)
          at android.app.ActivityThread.handleSendResult(ActivityThread.java:4103)
          at android.app.ActivityThread.access$1400(ActivityThread.java:177)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1497)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:145)
          at android.app.ActivityThread.main(ActivityThread.java:5944)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
   Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/7963 from pid=16802, uid=10409 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
  </code></pre>
  
  <p>Below are the codes invoking the gallery:</p>
  
  <pre><code>public void onActivityResult(int request, int response, Intent data) {
      super.onActivityResult(request, response, data);
      if(response == RESULT_OK) {
          if(request == SELECT_PICTURE) {
              Uri selectedImage = data.getData();
              selectedImagePath = getPath(selectedImage);
          }
      }
  }
  
  public String getPath(Uri uri) {
      // just some safety built in
      if( uri == null ) {
          // TODO perform some logging or show user feedback
          return null;
      }
      // try to retrieve the image from the media store first
      // this will only work for images selected from gallery
      String[] projection = { MediaStore.Images.Media.DATA };
      Cursor cursor = managedQuery(uri, projection, null, null, null);
      if( cursor != null ){
          int column_index = cursor
                  .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
          cursor.moveToFirst();
          return cursor.getString(column_index);
      }
      // this is our fallback here
      return uri.getPath();
  }
  
  @Override
  public void imageUpload() {
      runOnUiThread(new Runnable() {
          @Override
          public void run() {
              Intent intent = new Intent();
              intent.setType("image/");
              intent.setAction(Intent.ACTION_GET_CONTENT);
              startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
          }
      });
  
  }
  </code></pre>
  
  <p>Then I simply call that method in one of my screen classes:</p>
  
  <pre><code>boxImage1.addListener(new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
              imageUpload();
          }
      });
  }
  </code></pre>
  
  <p>So what I'm asking is: How can I make a click on a picture to upload that actual picture into say a texture or something? I just want their chosen image to be drawn on the screen when they pick it.</p>