I tried with the following code but it is not attaching the pdf file.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setType("text/plain");
if (isOnlyWhatsApp) {
sendIntent.setPackage("com.whatsapp");
}
Uri uri = Uri.fromFile(attachment);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
activity.startActivity(sendIntent);
To send your compressed PDF via WhatsApp, select the file, then the Share icon. Choose your receiver and tap on the Send button. Easy!
Navigate to the PDF you wish to send. Tap the send icon on the top right portion of the screen. In the new dialog box, you have the option to share via email, or you can send a copy via AirDrop, Messages, or other third-party apps such as WhatsApp.
Large files that exceed 100MB in size cannot be shared over WhatsApp. This is because, when you share a file, it is transferred through the servers from one chat to another. These servers simply do not have the ability to send large files such as long videos or PDFs or audio files that are bigger than 100 MB.
I had this issue where I was trying to open a pdf file from assets folder and I did not work, but when I tried to open from Download folder (for example), it actually worked, and here is an example of it:
File outputFile = new File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_DOWNLOADS), "example.pdf");
Uri uri = Uri.fromFile(outputFile);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/pdf");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setPackage("com.whatsapp");
activity.startActivity(share);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With