Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share pdf and text through whatsapp in android?

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);
like image 628
Sujeet Kumar Mehta Avatar asked Sep 16 '16 01:09

Sujeet Kumar Mehta


People also ask

Can you attach a PDF to a WhatsApp message?

To send your compressed PDF via WhatsApp, select the file, then the Share icon. Choose your receiver and tap on the Send button. Easy!

Can you send a PDF via text on Android?

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.

Why can't I share PDF via 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.


1 Answers

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);      
like image 79
KHALED Avatar answered Oct 22 '22 15:10

KHALED