Share PDF

Asked

Viewed 934 times

1

I have an application that generates a pdf from an internal content.

I need to share this pdf, and for that, I do it as follows:

 final String filePath = file.getAbsolutePath();
 final Uri arquivo = Uri.parse( filePath);
 final Intent _intent = new Intent();
            _intent.setAction(Intent.ACTION_SEND);
            _intent.putExtra(Intent.EXTRA_STREAM,  arquivo);
            _intent.putExtra(Intent.EXTRA_TEXT,  "Meu  PDF");
            _intent.putExtra(Intent.EXTRA_TITLE,   "Meu pdf");

            _intent.setType("application/pdf");

            startActivity(Intent.createChooser(_intent, "Compartilhar"));

Being the variable arquivo one Uri, with the file path, which is generated when opening the screen.

The Intent is called after the user’s click.

When I try to send by email, the file is not attached.

Displays a Toast saying it is not possible to attach an empty file.

But when I go to the folder, it opens normally!

How do I manage to share this pdf by email?

1 answer

0


The error occurs due to the way the Uri is caught from the file:

 final String filePath = file.getAbsolutePath();
 final Uri arquivo = Uri.parse( filePath);

For internal files should be used Uri.fromFile.

Example:

 final Uri arquivo = Uri.fromFile(file);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.