title: Send Image via Intent by WhatsApp - Wrong Image
body: <p>I thought that this is a popular problem, but I can't find anything related to it. So here is what I want:
  I'm trying to send an Image by WhatsApp with the following code:</p>
  
  <pre><code>public static void shareImage(Context context,Bitmap bitmap, String text){
      Intent share = new Intent(Intent.ACTION_SEND);
      share.setType("image/*");
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
      File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
      try {
          f.createNewFile();
          FileOutputStream fo = new FileOutputStream(f);
          fo.write(bytes.toByteArray());
          fo.close();
      } catch (IOException e) {                       
              e.printStackTrace();
      }
      share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
      share.setPackage("com.whatsapp");
      context.startActivity(Intent.createChooser(share, "Share!"));
  }
  </code></pre>
  
  <p>It works fine, for the first time I use the app.. the right image appear in WhatsApp. If I choose another Bitmap with my App, Whatsapp still shows the first Image.</p>
  
  <p>What I did and what I thought caused the problem:</p>
  
  <ul>
  <li>If the temporary file existed, I deleted it by <code>f.delete()</code></li>
  <li>Then I updated the Gallery with MediaScanner, because I thought, that the URI I put in Extra is not up to date... </li>
  </ul>
  
  <p>Fyi: The temporary file contains the right Image: If I choose it with an FileExplorer it shows the right image.. if I try to send the Image.. still the old Image</p>
  
  <p>Does anyone has an idea what the problem might be? Is the Uri wrong? If I print <code>Uri.fromFile(f)</code>it says  <code>file:///storage/sdcard0/temporary_file.jpg</code></p>
  
  <p>Thank you!</p>
  
  <p>Nico</p>