title: Attach image using Intent.ACTION_SEND
body: <p>I'm trying to attach an image using different applications with the following code:</p>
  
  <pre><code>val sendIntent = Intent(Intent.ACTION_SEND)
  sendIntent.putExtra(Intent.EXTRA_TEXT, "Test example")
  sendIntent.type = "image/png"
  sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(logo.absolutePath))
  startActivity(sendIntent)
  </code></pre>
  
  <p>The image that is attached is generated with this code:</p>
  
  <pre><code>// Generate file for application logo
  val path = Environment.getExternalStorageDirectory().absolutePath
  val logo = File(path, "logo.png")
  
  // If logo doesn't exist
  if (!logo.exists())
  {
      // Create new file
      logo.createNewFile()
  
      // Save application logo to new file
      val fOut = FileOutputStream(logo)
      val image = BitmapFactory.decodeResource(applicationContext.resources, R.mipmap.ic_launcher_round)
      image.compress(Bitmap.CompressFormat.PNG, 100, fOut)
      fOut.flush()
      fOut.close()
  }
  </code></pre>
  
  <p>But when I try to open GMAIL with this intent, only text shows app with an error: <code>Couldn't attach file</code>.</p>
  
  <p>What am I missing?</p>
  
  <blockquote>
    <p>EDIT</p>
  </blockquote>
  
  <p>Here is another solution: <a href="https://stackoverflow.com/questions/42251634/android-os-fileuriexposedexception-file-jpg-exposed-beyond-app-through-clipdata/45569709#45569709">android.os.FileUriExposedException: file.jpg exposed beyond app through ClipData.Item.getUri()</a></p>
  
  <pre><code>StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
  StrictMode.setVmPolicy(builder.build());
  </code></pre>