title: Android:Failed to load attachment error?
body: <p>I am able to take a screenshot of my activity and store the file
  but when i try to share it, it gives me Failed to load attachment.
  I am new at android. Any help will be useful. </p>
  
  <p>this is my code:</p>
  
  <pre><code> public Bitmap takeScreenshot() {
      View rootView =  getWindow().getDecorView().findViewById(android.R.id.content).getRootView();
      rootView.setDrawingCacheEnabled(true);
      Bitmap bitmap = Bitmap.createBitmap(rootView.getDrawingCache());
      rootView.setDrawingCacheEnabled(false);
      Log.i("Screenshot","TAKEN");
      return bitmap;
  
  }
  
  public void saveBitmap(Bitmap bitmap) {
      imagePath = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/screenshot.png");
      FileOutputStream fos;
      try {
          fos = new FileOutputStream(imagePath);
          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
          Log.i("Screenshot","SAVED at"+imagePath);
          fos.flush();
          fos.close();
      } catch (IOException e) {
          Log.e("GREC", e.getMessage(), e);
      }
  }
  
  private void shareIt() {
      Uri uri = Uri.fromFile(imagePath);
      Intent sharingIntent = new Intent(Intent.ACTION_SEND);
      sharingIntent.setType("image/*");
      String shareBody = "My highest score is ";
      sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "My score");
      sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
      sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
      Log.i("IMAGE SHARING","TRY...");
  
      try {
          startActivity(Intent.createChooser(sharingIntent, "Share via"));
      }catch(Exception e){
          Log.i("try","failed");
          Toast.makeText(getApplicationContext(), "No App Available", Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>It is not giving me an error but when i try to share it, it gives me "failed to load attachment". Where am I going wrong?</p>
  
  <p>LOG</p>
  
  <p>01-20 21:10:53.689 3553-3582/com.quickyy.guess.com.quickyy W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xac3d5c60, error=EGL_BAD_MATCH</p>
  
  <p>01-20 21:10:53.886 3553-3582/com.quickyy.guess.com.quickyy E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb40974e0</p>
  
  <p>01-20 21:10:55.259 3553-3553/com.quickyy.guess.com.quickyy I/Screenshot: TAKEN</p>
  
  <p>01-20 21:10:55.340 3553-3553/com.quickyy.guess.com.quickyy I/Screenshot: SAVED at/storage/emulated/0/screenshot.png</p>
  
  <p>01-20 21:10:55.506 3553-3553/com.quickyy.guess.com.quickyy I/IMAGE SHARING: TRY...</p>
  
  <p>01-20 21:10:58.858 3553-3582/com.quickyy.guess.com.quickyy E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb4097a90</p>
  
  <p>01-20 21:11:03.767 3553-3582/com.quickyy.guess.com.quickyy E/EGL_emulation: tid 3582: eglSurfaceAttrib(1165): error 0x3009 (EGL_BAD_MATCH)</p>
  
  <p>01-20 21:11:03.767 3553-3582/com.quickyy.guess.com.quickyy W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xac3d5c60, error=EGL_BAD_MATCH</p>