title: Pick Image From Gallery Or Google Photos Failing
body: <p><strong>EDIT:</strong> I wanted to update what the problem really is. On a Samsung phone you have "Gallery", inside "Gallery" you can also see your google photos backups. This is the photo selection I'm trying to get at. Now on other apps (Close5) they simply display a message stating
   <strong>"That photo is not supported"</strong>. But why? Why can't we get this url (https:/lh3.googleusercontent) to work?</p>
  
  <blockquote>
    <p>E/BitmapFactory: Unable to decode stream:
    java.io.FileNotFoundException:
    /https:/lh3.googleusercontent.com/-Llgk8Mqk-rI/U8LK0SMnpWI/AAAAAAAAFk4/0cktb59DnL8GgblJ-IJIUBDuP9MQXCBPACHM/I/IMG_20140711_085012.jpg:
    open failed: ENOENT (No such file or directory)</p>
  </blockquote>
  
  <p><strong>You can all clearly see this is a real photo with a real url:</strong></p>
  
  <pre><code>https:/lh3.googleusercontent.com/-Llgk8Mqk-rI/U8LK0SMnpWI/AAAAAAAAFk4/0cktb59DnL8GgblJ-IJIUBDuP9MQXCBPACHM/I/IMG_20140711_085012.jpg
  </code></pre>
  
  <p>Everything works fine until I go to select from photos or a google photos image instead of from the gallery, I tried handling the exception (<code>Sorry, that image isn't supported. Try another gallery!</code>) but that seems incomplete. I tried looking at other solutions on here but none of them worked for google photos. Thanks!</p>
  
  <p>Error is a null pointer with:</p>
  
  <blockquote>
    <p>app E/BitmapFactory: Unable to decode stream:
    java.io.FileNotFoundException: /https:/lh3.googleusercontent</p>
  </blockquote>
  
  <pre><code> @Override
      public void onActivityResult(int requestCode, int resultCode,
                                      Intent data) {
          if (resultCode != Activity.RESULT_CANCELED) {
                  if (requestCode == 1) {
                      try{
                      String selectedImagePath = getAbsolutePath(data.getData());                          ((PostAdParentTabHost)getActivity()).getMap_of_picture_paths().put(1, selectedImagePath);                      
                      post_ad_camera_img_1.setImageBitmap(decodeSampledBitmapFromFileToCustomSize(selectedImagePath, 150, 150));
                      animation_master.fade(post_ad_camera_img_1);
                      }catch(Exception e){
                          e.printStackTrace();
                          ((PostAdParentTabHost)getActivity()).getMap_of_picture_paths().remove(requestCode);
                          Toast.makeText(getActivity(), "Sorry, that image isn't supported. Try another gallery! ", Toast.LENGTH_SHORT).show();
                      }
  
  //------------------------------------------------------Methods:
  public String getAbsolutePath(Uri uri) {
      Uri final_uri = uri;
          if (uri.getLastPathSegment().contains("googleusercontent.com")){
              final_uri = getImageUrlWithAuthority(getActivity(), uri);
              String[] projection = { MediaStore.MediaColumns.DATA };
              Cursor cursor = getActivity().getContentResolver().query(final_uri, projection, null, null, null);
              if (cursor != null) {
                  int column_index = cursor
                          .getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
                  cursor.moveToFirst();
                  return cursor.getString(column_index);
              }else{
  
                  return null;
              }
          }else{
          String[] projection = { MediaStore.MediaColumns.DATA };
          Cursor cursor = getActivity().getContentResolver().query(final_uri, projection, null, null, null);
          if (cursor != null) {
              int column_index = cursor
                      .getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
              cursor.moveToFirst();
              return cursor.getString(column_index);
          }else{
  
              return null;
          }
  
      }
  
   public static Uri getImageUrlWithAuthority(Context context, Uri uri) {
      InputStream is = null;
      if (uri.getAuthority() != null) {
          try {
              is = context.getContentResolver().openInputStream(uri);
              Bitmap bmp = BitmapFactory.decodeStream(is);
              return writeToTempImageAndGetPathUri(context, bmp);
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }finally {
              try {
                  is.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
      return null;
  }
  
  public static Uri writeToTempImageAndGetPathUri(Context inContext, Bitmap inImage) {
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
      String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
      return Uri.parse(path);
  }
  
        public Uri setImageUri() {
          // Store image in dcim
          File file = new File(Environment.getExternalStorageDirectory()
                  + "/DCIM/", "image" + new Date().getTime() + ".png");
          Uri imgUri = Uri.fromFile(file);
          this.image_as_uri_for_parcel = imgUri;
          this.imgPath = file.getAbsolutePath();
          return imgUri;
  
  }
  </code></pre>