Forward image URI intent
<p>I'm developing an app that fills an email template and adds a picture. I want to use the app as follows: from the gallery, I share an image with my app via ACTION_SEND. My app does some processing and then shares an email with attachment.</p>

<p>Now I'm trying to simply get the image Uri and pass it on, but then I get a SecurityException.</p>

<pre><code>protected void onCreate(Bundle savedInstanceState) {
   // Read the incoming intent
   Intent intent = getIntent();
   String action = intent.getAction();
   String type = intent.getType();
   Uri imageUri;

   if (Intent.ACTION_SEND.equals(action) &amp;&amp; type != null) {
        if (type.startsWith("image/")) {
            imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        }
    }

   // Create the outgoing intent
   Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType("message/rfc822");
    if(imageUri != null){
        emailIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    }

    startActivity(Intent.createChooser(emailIntent, getString(R.string.chooserText)));
}
</code></pre>

<p>Logging:</p>

<pre><code>02-12 14:07:11.196 10241-10241/? E/ResolverActivity: Unable to launch as uid 10156 package ***, while running in android:ui
java.lang.SecurityException: Uid 10156 does not have permission to uri 0 @ content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F19546/FORMAT_JPEG/778368258
</code></pre>

<p>What would be the right way to do this? I have tried setting flags and permissions, but I can't find how to do this exactly.</p>