Share PDF

1

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

I need to share this pdf , and for this I do the following:

 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 a Uri , with the path of the file, which is generated when you open the screen.

The intent is called after the user click.

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

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

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

How do I get this pdf to share?

    
asked by anonymous 29.11.2016 / 17:01

1 answer

0

The error occurs because of the way the Uri is taken from the file:

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

For internal files you should use Uri.fromFile .

Example:

 final Uri arquivo = Uri.fromFile(file);
    
29.11.2016 / 18:42