2

I need an Intent to send a file to apps such as messengers (WhatsApp, etc.) and Email clients (Gmail, etc.) at the same time. Gmail however for some reason I don't understand shows the file uri in the recipient field.

My original uri is: [package_name].debug.generic.tools.GenericFileProvider/external_files/1544617983061.pdf

The recipient end up as: //[package_name].debug.generic.tools.GenericFileProvider/external_files/1544617983061.pdf

Screenshot from Gmail:

enter image description here

Code with some bug:

Uri uri = FileProvider.getUriForFile(fragment.getActivity(), fragment.getActivity().getApplicationContext().getPackageName() + ".generic.tools.GenericFileProvider", externalFile);
Intent intentSend = new Intent(Intent.ACTION_SEND);
intentSend.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intentSend.setDataAndType(uri, "application/pdf");
intentSend.putExtra(Intent.EXTRA_STREAM, uri);
intentSend.putExtra(Intent.EXTRA_SUBJECT, name);
intentSend.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@provider.com"});

try {
    fragment.startActivity(Intent.createChooser(intentSend, fragment.getString(R.string.external_file_send_chooser)));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(fragment.getActivity(), R.string.external_file_send_no_activity, Toast.LENGTH_LONG).show();
}

Does anyone understand what is going on? How come my data uri is interpreted as recipient?

The file itself is attached correctly to the Email and WhatsApp also successfully sends the file.

EDIT: Question has already been answered here: Content URI passed in EXTRA_STREAM appears to "To:" email field

Oliver Metz
  • 2,712
  • 2
  • 20
  • 32
  • Question is a duplicate. It was already answered [here](https://stackoverflow.com/questions/39898556/content-uri-passed-in-extra-stream-appears-to-to-email-field). – Oliver Metz Dec 18 '18 at 21:27

0 Answers0