I am creating a file in the cache directory that I'd like to share with others (via Gmail / WhatsApp etc). I am able to do this using FileProvider, and it works OK for WhatsApp. When choosing to share on Gmail the photo is correctly attached, but the Uri that I pass via Intent.EXTRA_STREAM also ends up being parsed by Gmail as an address in the "To:" field of the newly composed email, along with the address(es) that I pass via Intent.EXTRA_EMAIL.
So the user is required to delete the bogus (Uri) email address before sending. Any idea how to prevent this from happening?
Uri contentUri = FileProvider.getUriForFile(getActivity(), "com.mypackage.fileprovider", cacheFile);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setDataAndType(contentUri, "image/jpeg");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"some_address@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Photo");
intent.putExtra(Intent.EXTRA_TEXT, "Check out this photo");
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
if(intent.resolveActivity(getActivity().getPackageManager()) != null)
{
startActivity(Intent.createChooser(intent, getString(R.string.share_file)));
}