title: onActivityResult not working on API 23
body: <p>The onActivityResult method returns blank data or is not called when picking an image from Gallery. My implementation works fine on API 16, 17...22 but I am having problems with API 23. I read this article: <a href="https://guides.codepath.com/android/Accessing-the-Camera-and-Stored-Media" rel="nofollow noreferrer">https://guides.codepath.com/android/Accessing-the-Camera-and-Stored-Media</a> , about permissions. </p>
  
  <p>My client has tested the app on 3 phones running Android 6 
  and they all have the same behavior when picking a image. You can see an activity screenshot, there are 3 ImageButtons (a big one, and 2 small ones), when user clicks on an ImageButton the gallery is triggered for picking an image, when user picks an image the ImageButton just gets grey instead of showing the picked image.</p>
  
  <pre><code>////onclick method///photo2 is a imagebutton////SELECT_PICTURE2 is the code
  
  photo2_evento.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
  
              Intent intent = new Intent();
              intent.setType("image/*");
              intent.setAction(Intent.ACTION_GET_CONTENT);
              //startActivityForResult(Intent.createChooser(intent, "Escoge
               una imagen"), SELECT_PICTURE2);
              startActivityForResult(intent, SELECT_PICTURE2);
  
          }
      });
  
  ///onactivityResult
      @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent
   data) {
             super.onActivityResult(requestCode, resultCode, data);
             if (resultCode == Activity.RESULT_OK) {
  
                try{
  
                 Uri selectedImageUri = data.getData();        
  
  
               if (requestCode == SELECT_PICTURE1) {
  
                     photo1_path = getRealPathFromURI(selectedImageUri);
                  photo1_evento.setImageBitmap(decodeSampledBitmapFromResource(photo1_path, 400, 400));
  
  
                  }else if(requestCode == SELECT_PICTURE2){
  
                      photo2_path = getRealPathFromURI(selectedImageUri);
                      photo2_evento.setImageBitmap(decodeSampledBitmapFromResource(photo2_path, 100, 100));
  
  
                  }else if(requestCode == SELECT_PICTURE3){
  
                      photo3_path = getRealPathFromURI(selectedImageUri);             
  
                      photo3_evento.setImageBitmap(decodeSampledBitmapFromResource(photo3_path, 100, 100)); 
  
  
  
                  }
  
                }catch(Exception e){
                    e.printStackTrace();
                }catch (OutOfMemoryError e) {
  
                    e.printStackTrace();
                    Toast.makeText(getBaseContext(),"memory error", Toast.LENGTH_LONG).show();
                }
  
  
                  }
  
  
  
  
  }
  
  ////decodeSampledBitmapFromResource is just a method provided by Google     Android for sizing images.
  
  ////this method is for getting the URI path, I got this code from stackoverflow
  public String getRealPathFromURI(Uri contentUri) {
  
  
         String[] projection = { MediaStore.Images.Media.DATA };
         Cursor cursor = null;
         try {
             if (Build.VERSION.SDK_INT &gt; 19) {
                 // Will return "image:x*"
                 String wholeID = DocumentsContract.getDocumentId(contentUri);
                 // Split at colon, use second item in the array
                 String id = wholeID.split(":")[1];
                 // where id is equal to
                 String sel = MediaStore.Images.Media._ID + "=?";
  
                 cursor = Publicar_Eventos.this.getContentResolver().query(
                         MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                         projection, sel, new String[] { id }, null);
             } else {
                 cursor = Publicar_Eventos.this.getContentResolver().query(contentUri,
                         projection, null, null, null);
             }
         } catch (Exception e) {
             e.printStackTrace();
         }catch (OutOfMemoryError e) {
  
             e.printStackTrace();
             Toast.makeText(getBaseContext(),"error de memoria", Toast.LENGTH_LONG).show();
         }
  
         String path = null;
         try {
             int column_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
             cursor.moveToFirst();
             path = cursor.getString(column_index).toString();
             cursor.close();
         } catch (NullPointerException e) {
             e.printStackTrace();
         }
         return path;
     }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/TzIlz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TzIlz.jpg" alt="enter image description here"></a></p>